0
0
Fork 0

Make Rubella::Input classes respond to each

Also fix some code convetions
This commit is contained in:
Stormwind 2015-04-25 22:41:05 +02:00
parent 9b4ad30a7e
commit 9a013f53fd
2 changed files with 12 additions and 9 deletions

View File

@ -20,7 +20,7 @@ module Rubella
# @param value string A string, which contains the data # @param value string A string, which contains the data
# @return Rubella::Input::Base # @return Rubella::Input::Base
# #
def self.string(value) def self.string value
raise NotImplementedError.new "Please override 'self.string' in your "+ raise NotImplementedError.new "Please override 'self.string' in your "+
"concrete implementation" "concrete implementation"
end end
@ -32,11 +32,14 @@ module Rubella
# @param file_name string The name of the file # @param file_name string The name of the file
# @return Rubella:Input::Base # @return Rubella:Input::Base
# #
def self.file(file_name) def self.file file_name
raise NotImplementedError.new "Please override 'self.file' in your "+ raise NotImplementedError.new "Please override 'self.file' in your "+
"concrete implementation" "concrete implementation"
end end
def each &block
@data.each &block
end
end end

View File

@ -14,11 +14,11 @@ module Rubella
# is supposed to be private. Please use Rubella::Input::JSON.string or # is supposed to be private. Please use Rubella::Input::JSON.string or
# Rubella::Input::JSON.file to create a new instance. # Rubella::Input::JSON.file to create a new instance.
# #
# @param json__string string A string, which contains the data as json # @param json_string string A string, which contains the data as json
# @return Rubella::Input::JSON # @return Rubella::Input::JSON
# #
def initialize(json_string) def initialize json_string
@data = ::JSON::load(json_string) @data = ::JSON::load json_string
end end
# Constructor # Constructor
@ -26,8 +26,8 @@ module Rubella
# #
# @param json_string string A string, which contains the data as json # @param json_string string A string, which contains the data as json
# @return Rubella::Input::JSON # @return Rubella::Input::JSON
def self.string(json_string) def self.string json_string
self.new(json_string) self.new json_string
end end
# Constructor # Constructor
@ -37,8 +37,8 @@ module Rubella
# @param json_file string The name of the file, which json contains # @param json_file string The name of the file, which json contains
# @return Rubella:Input::JSON # @return Rubella:Input::JSON
# #
def self.file(json_file) def self.file json_file
self.new File.new(json_file, 'r') self.new File.new json_file, 'r'
end end
end end