Class: SportsDataApi::JsonData

Inherits:
Object
  • Object
show all
Defined in:
lib/sports_data_api/json_data.rb

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ JsonData



3
4
5
6
7
8
9
10
# File 'lib/sports_data_api/json_data.rb', line 3

def initialize(json)
  attr_name = class_name
  ivar = self.instance_variable_set("@#{attr_name}", {})
  self.class.class_eval { attr_reader :"#{attr_name}" }
  json.each_pair do |attr_name, attr_value|
    ivar[attr_name.to_sym] = attr_value
  end
end

Instance Method Details

#[](key) ⇒ Object



12
13
14
# File 'lib/sports_data_api/json_data.rb', line 12

def [](key)
  self.instance_variable_get("@#{class_name}")[key]
end