Class: Fantasydata::Base
- Inherits:
-
Object
- Object
- Fantasydata::Base
- Defined in:
- lib/fantasydata/base.rb
Direct Known Subclasses
ByeWeek, DailyFantasyPlayer, DailyFantasyPlayerStats, DailyFantasyPoints, FantasyPlayerAdp, GameStat, Injury, News, PlayerDetail, PlayerGameStat, PlayerSeasonStat, Schedule, ScoringDetail, Stadium, Standings, TeamDetail, TeamGameStat, TeamSeasonStat, Timeline
Class Method Summary collapse
-
.attr_reader(*attrs) ⇒ Object
Define methods that retrieve the value from an initialized instance variable Hash, using the attribute as a key.
Instance Method Summary collapse
- #==(other) ⇒ Boolean
-
#attrs ⇒ Hash
(also: #to_hash)
Retrieve the attributes of an object.
-
#initialize(attrs = {}) ⇒ Fantasydata::Base
constructor
Initializes a new object.
-
#update(attrs) ⇒ Fantasydata::Base
Update the attributes of an object.
Constructor Details
#initialize(attrs = {}) ⇒ Fantasydata::Base
Initializes a new object
33 34 35 36 37 38 39 |
# File 'lib/fantasydata/base.rb', line 33 def initialize(attrs={}) new_attrs = {} attrs.to_hash.each_pair do |k,v| new_attrs.merge!({underscore_key(k) => v}) end @attrs = new_attrs end |
Class Method Details
.attr_reader(*attrs) ⇒ Object
Define methods that retrieve the value from an initialized instance variable Hash, using the attribute as a key
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/fantasydata/base.rb', line 6 def self.attr_reader(*attrs) #@attr_readers ||= [] #@attr_readers.concat attrs mod = Module.new do attrs.each do |attribute| define_method attribute do @attrs[attribute.to_sym] if @attrs end define_method "#{attribute}?" do !!@attrs[attribute.to_sym] end end end const_set(:Attributes, mod) include mod end |
Instance Method Details
#==(other) ⇒ Boolean
25 26 27 |
# File 'lib/fantasydata/base.rb', line 25 def ==(other) super || attr_equal(:id, other) || attrs_equal(other) end |
#attrs ⇒ Hash Also known as: to_hash
Retrieve the attributes of an object
44 45 46 |
# File 'lib/fantasydata/base.rb', line 44 def attrs @attrs end |
#update(attrs) ⇒ Fantasydata::Base
Update the attributes of an object
53 54 55 56 |
# File 'lib/fantasydata/base.rb', line 53 def update(attrs) @attrs.update(attrs) self end |