Class: Echowrap::Base
- Inherits:
-
Object
- Object
- Echowrap::Base
- Defined in:
- lib/echowrap/base.rb
Direct Known Subclasses
Analysis, Artist, Asset, AudioSummary, Biography, Blog, CallList, CategoryMap, DocCounts, EchonestId, Familiarity, Feed, ForeignId, Genre, Hotttnesss, Image, Item, ItemRequest, Keyvalues, License, Location, Meta, NewsArticle, Options, Playlist, Prediction, Reference, Review, Rule, Sandbox, Seeds, SequencedData, Song, Status, TasteProfile, Term, Track, UpdateInfo, Urls, Video, YearsActive
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 = {}) ⇒ Echowrap::Base
constructor
Initializes a new object.
-
#update(attrs) ⇒ Echowrap::Base
Update the attributes of an object.
Constructor Details
#initialize(attrs = {}) ⇒ Echowrap::Base
Initializes a new object
34 35 36 |
# File 'lib/echowrap/base.rb', line 34 def initialize(attrs={}) @attrs = 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 22 |
# File 'lib/echowrap/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
26 27 28 |
# File 'lib/echowrap/base.rb', line 26 def ==(other) super || attr_equal(:id, other) || attrs_equal(other) end |
#attrs ⇒ Hash Also known as: to_hash
Retrieve the attributes of an object
41 42 43 |
# File 'lib/echowrap/base.rb', line 41 def attrs @attrs end |
#update(attrs) ⇒ Echowrap::Base
Update the attributes of an object
50 51 52 53 |
# File 'lib/echowrap/base.rb', line 50 def update(attrs) @attrs.update(attrs) self end |