0
0
Fork 0
rubella/lib/rubella/input/json.rb

48 lines
1.3 KiB
Ruby
Raw Normal View History

require 'rubella/input/base'
require 'json'
module Rubella
module Input
# Gets data in JSON formate and translate it into a Ruby readable form to
# make it possible to handle the data.
#
class JSON < Base
2015-02-19 22:40:38 +01:00
# Constructor
# This constructer can create a new Rubella::Input::JSON object, but it
# is supposed to be private. Please use Rubella::Input::JSON.string or
# Rubella::Input::JSON.file to create a new instance.
#
# @param json_string string A string, which contains the data as json
2015-02-19 22:40:38 +01:00
# @return Rubella::Input::JSON
#
def initialize json_string
@data = ::JSON::load json_string
end
2015-02-19 22:40:38 +01:00
# Constructor
# Creates a new Rubella::Input::JSON object, from the given json.
#
# @param json_string string A string, which contains the data as json
# @return Rubella::Input::JSON
def self.string json_string
self.new json_string
end
2015-02-19 22:40:38 +01:00
# Constructor
# Creates a new Rubella::Input::JSON object, from the given file.
# Only the file name is required.
#
# @param json_file string The name of the file, which json contains
# @return Rubella:Input::JSON
#
def self.file json_file
self.new File.new json_file, 'r'
end
end
end
2015-10-22 12:11:16 +02:00
end