Class: Coach4rb::Resource::Subscription
- Defined in:
- lib/coach4rb/resource/subscription.rb
Instance Attribute Summary collapse
-
#datesubscribed ⇒ Object
(also: #created)
Returns the value of attribute datesubscribed.
-
#entries ⇒ Object
Returns the value of attribute entries.
-
#id ⇒ Object
Returns the value of attribute id.
-
#partnership ⇒ Object
Returns the value of attribute partnership.
-
#publicvisble ⇒ Object
(also: #visible)
Returns the value of attribute publicvisble.
-
#sport ⇒ Object
Returns the value of attribute sport.
-
#uri ⇒ Object
Returns the value of attribute uri.
Attributes inherited from Entity
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from Entity
Methods included from Mixin::AsHash
Methods included from Mixin::Iterable
Methods included from Mixin::AutoConstructor
Instance Attribute Details
#datesubscribed ⇒ Object Also known as: created
Returns the value of attribute datesubscribed.
6 7 8 |
# File 'lib/coach4rb/resource/subscription.rb', line 6 def datesubscribed @datesubscribed end |
#entries ⇒ Object
Returns the value of attribute entries.
6 7 8 |
# File 'lib/coach4rb/resource/subscription.rb', line 6 def entries @entries end |
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/coach4rb/resource/subscription.rb', line 6 def id @id end |
#partnership ⇒ Object
Returns the value of attribute partnership.
6 7 8 |
# File 'lib/coach4rb/resource/subscription.rb', line 6 def partnership @partnership end |
#publicvisble ⇒ Object Also known as: visible
Returns the value of attribute publicvisble.
6 7 8 |
# File 'lib/coach4rb/resource/subscription.rb', line 6 def publicvisble @publicvisble end |
#sport ⇒ Object
Returns the value of attribute sport.
6 7 8 |
# File 'lib/coach4rb/resource/subscription.rb', line 6 def sport @sport end |
#uri ⇒ Object
Returns the value of attribute uri.
6 7 8 |
# File 'lib/coach4rb/resource/subscription.rb', line 6 def uri @uri end |
Class Method Details
.from_coach(a_hash) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/coach4rb/resource/subscription.rb', line 13 def self.from_coach(a_hash) new_hash = a_hash.dup new_hash[:datesubscribed] = Time.at(a_hash[:datesubscribed]/1000).to_datetime rescue nil new_hash[:partnership] = Resource::Partnership.from_coach(new_hash[:partnership]) rescue nil new_hash[:user] = Resource::User.from_coach(new_hash[:user]) rescue nil new_hash[:entries] = new_hash[:entries].map {|a_hash| Resource::Entry.from_coach a_hash} rescue [] new_hash[:sport] = Resource::Sport.from_coach(new_hash[:sport]) rescue nil super new_hash end |
Instance Method Details
#entity_path ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/coach4rb/resource/subscription.rb', line 33 def entity_path if @user "/users/#{@user.username}/#{@sport}" elsif @partnership "/partnerships/#{@partnership.first_user.username};#{@partnership.second_user.username}/#{@sport}" else raise 'Error: cannot create url!' end end |
#sport?(sport) ⇒ Boolean
24 25 26 27 28 29 30 |
# File 'lib/coach4rb/resource/subscription.rb', line 24 def sport?(sport) raise 'Error: Invalid sport param!' if sport.nil? *, subscription_sport = uri.split('/') # get last part of the uri subscription_sport = subscription_sport.downcase.to_sym sport = sport.to_s.downcase.to_sym sport == subscription_sport end |