Class: SportsDataApi::JsonData
- Inherits:
-
Object
- Object
- SportsDataApi::JsonData
- Defined in:
- lib/sports_data_api/json_data.rb
Direct Known Subclasses
Golf::Player, Golf::Round, Golf::Score, Ncaafb::Player, Nfl::Player
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(json) ⇒ JsonData
constructor
A new instance of JsonData.
Constructor Details
#initialize(json) ⇒ JsonData
Returns a new instance of 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 |