Class: LandbResponse
- Inherits:
-
Object
- Object
- LandbResponse
- Defined in:
- lib/landb/landb_responce.rb
Instance Method Summary collapse
- #get_value_for_path(path_array) ⇒ Object
- #get_values_for_paths(paths_array) ⇒ Object
-
#initialize(hash) ⇒ LandbResponse
constructor
A new instance of LandbResponse.
Constructor Details
#initialize(hash) ⇒ LandbResponse
Returns a new instance of LandbResponse.
3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/landb/landb_responce.rb', line 3 def initialize(hash) hash.each do |k,v| next if k.to_s =~ /@|:/ if v.instance_of? Hash self.instance_variable_set("@#{k}", LandbResponse.new(v)) ## create and initialize an instance variable for this hash. else self.instance_variable_set("@#{k}", v) ## create and initialize an instance variable for this key/value pair. end self.class.send(:define_method, k, proc{self.instance_variable_get("@#{k}")}) ## create the getter that returns the instance variable self.class.send(:define_method, "#{k}=", proc{|v| self.instance_variable_set("@#{k}", v)}) ## create the setter that sets the instance variable end end |
Instance Method Details
#get_value_for_path(path_array) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/landb/landb_responce.rb', line 27 def get_value_for_path path_array responce_runner = self path_array.each do |domain| responce_runner = responce_runner.send domain.to_sym end responce_runner end |
#get_values_for_paths(paths_array) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/landb/landb_responce.rb', line 17 def get_values_for_paths paths_array responces = [] paths_array.each do |path| responces << get_value_for_path(path) end responces end |