Class: AppleMusic::Resource
- Inherits:
-
Object
- Object
- AppleMusic::Resource
- Defined in:
- lib/apple_music/resource.rb
Overview
Direct Known Subclasses
Activity, Album, AppleCurator, Artist, Curator, Genre, MusicVideo, Playlist, Preview, Song, Station, Storefront
Defined Under Namespace
Classes: InvalidTypeError
Constant Summary collapse
- RESOURCE_MAP =
{ 'activities' => 'AppleMusic::Activity', 'albums' => 'AppleMusic::Album', 'apple-curators' => 'AppleMusic::AppleCurator', 'artists' => 'AppleMusic::Artist', 'curators' => 'AppleMusic::Curator', 'genres' => 'AppleMusic::Genre', 'music-videos' => 'AppleMusic::MusicVideo', 'playlists' => 'AppleMusic::Playlist', 'songs' => 'AppleMusic::Song', 'stations' => 'AppleMusic::Station', 'storefronts' => 'AppleMusic::Storefront' }.freeze
Class Attribute Summary collapse
-
.attributes_model ⇒ Object
Returns the value of attribute attributes_model.
-
.relationships_model ⇒ Object
Returns the value of attribute relationships_model.
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#href ⇒ Object
readonly
Returns the value of attribute href.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#relationships ⇒ Object
readonly
Returns the value of attribute relationships.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(props = {}) ⇒ Resource
constructor
A new instance of Resource.
Constructor Details
#initialize(props = {}) ⇒ Resource
Returns a new instance of Resource.
33 34 35 36 37 38 39 |
# File 'lib/apple_music/resource.rb', line 33 def initialize(props = {}) @href = props['href'] @id = props['id'] @type = props['type'] @attributes = self.class.attributes_model.new(props['attributes']) if props['attributes'] @relationships = self.class.relationships_model.new(props['relationships']) if props['relationships'] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object (private)
43 44 45 46 47 48 49 50 51 |
# File 'lib/apple_music/resource.rb', line 43 def method_missing(name, *args, &block) if attributes.respond_to?(name) attributes.send(name, *args, &block) elsif relationships.respond_to?(name) relationships.send(name, *args, &block) else super end end |
Class Attribute Details
.attributes_model ⇒ Object
Returns the value of attribute attributes_model.
23 24 25 |
# File 'lib/apple_music/resource.rb', line 23 def attributes_model @attributes_model end |
.relationships_model ⇒ Object
Returns the value of attribute relationships_model.
23 24 25 |
# File 'lib/apple_music/resource.rb', line 23 def relationships_model @relationships_model end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
31 32 33 |
# File 'lib/apple_music/resource.rb', line 31 def attributes @attributes end |
#href ⇒ Object (readonly)
Returns the value of attribute href.
31 32 33 |
# File 'lib/apple_music/resource.rb', line 31 def href @href end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
31 32 33 |
# File 'lib/apple_music/resource.rb', line 31 def id @id end |
#relationships ⇒ Object (readonly)
Returns the value of attribute relationships.
31 32 33 |
# File 'lib/apple_music/resource.rb', line 31 def relationships @relationships end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
31 32 33 |
# File 'lib/apple_music/resource.rb', line 31 def type @type end |
Class Method Details
.build(props) ⇒ Object
25 26 27 28 |
# File 'lib/apple_music/resource.rb', line 25 def build(props) class_name = RESOURCE_MAP[props['type']] || raise(InvalidTypeError, "#{props['type']} type is undefined.") const_get(class_name).new(props) end |