From 9a013f53fdbbd10238d774ead95e6f569a373a6f Mon Sep 17 00:00:00 2001 From: Stormwind Date: Sat, 25 Apr 2015 22:41:05 +0200 Subject: [PATCH] Make Rubella::Input classes respond to each Also fix some code convetions --- lib/rubella/input/base.rb | 7 +++++-- lib/rubella/input/json.rb | 14 +++++++------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/rubella/input/base.rb b/lib/rubella/input/base.rb index fc24218..66895fb 100644 --- a/lib/rubella/input/base.rb +++ b/lib/rubella/input/base.rb @@ -20,7 +20,7 @@ module Rubella # @param value string A string, which contains the data # @return Rubella::Input::Base # - def self.string(value) + def self.string value raise NotImplementedError.new "Please override 'self.string' in your "+ "concrete implementation" end @@ -32,11 +32,14 @@ module Rubella # @param file_name string The name of the file # @return Rubella:Input::Base # - def self.file(file_name) + def self.file file_name raise NotImplementedError.new "Please override 'self.file' in your "+ "concrete implementation" end + def each &block + @data.each &block + end end diff --git a/lib/rubella/input/json.rb b/lib/rubella/input/json.rb index 99f2143..91ad4c1 100644 --- a/lib/rubella/input/json.rb +++ b/lib/rubella/input/json.rb @@ -14,11 +14,11 @@ module Rubella # 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 + # @param json_string string A string, which contains the data as json # @return Rubella::Input::JSON # - def initialize(json_string) - @data = ::JSON::load(json_string) + def initialize json_string + @data = ::JSON::load json_string end # Constructor @@ -26,8 +26,8 @@ module Rubella # # @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) + def self.string json_string + self.new json_string end # Constructor @@ -37,8 +37,8 @@ module Rubella # @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') + def self.file json_file + self.new File.new json_file, 'r' end end