Class: CyberCoach::Entry
- Inherits:
-
Resource
- Object
- AbstractResource
- Resource
- CyberCoach::Entry
- Includes:
- PostCreateable
- Defined in:
- lib/cybercoach/entry.rb
Overview
An Entry is submitted to a Subscription to represent a finished activity of a specific duration at a specific location.
Instance Attribute Summary collapse
-
#comment ⇒ Object
:attr: date_modified The date it was modified the last time.
-
#date_created ⇒ Object
:attr: date_modified The date it was modified the last time.
-
#date_modified ⇒ Object
:attr: date_modified The date it was modified the last time.
-
#duration ⇒ Object
:attr: date_modified The date it was modified the last time.
-
#location ⇒ Object
:attr: date_modified The date it was modified the last time.
-
#privacy_level ⇒ Object
:attr: date_modified The date it was modified the last time.
-
#subscription ⇒ Object
:attr: date_modified The date it was modified the last time.
Attributes inherited from Resource
Attributes inherited from AbstractResource
Instance Method Summary collapse
-
#from_serializable(serializable) ⇒ Object
:category: Serialization.
-
#plural_name ⇒ Object
:category: Configuration.
-
#resource_base_uri ⇒ Object
:category: Configuration.
-
#singular_name ⇒ Object
:category: Configuration.
-
#to_serializable ⇒ Object
:category: Serialization.
Methods included from PostCreateable
Methods inherited from Resource
Methods inherited from AbstractResource
#deserialize, #initialize, #read, #serialize
Constructor Details
This class inherits a constructor from CyberCoach::AbstractResource
Instance Attribute Details
#comment ⇒ Object
:attr: date_modified The date it was modified the last time.
48 49 50 |
# File 'lib/cybercoach/entry.rb', line 48 def comment @comment end |
#date_created ⇒ Object
:attr: date_modified The date it was modified the last time.
48 49 50 |
# File 'lib/cybercoach/entry.rb', line 48 def date_created @date_created end |
#date_modified ⇒ Object
:attr: date_modified The date it was modified the last time.
48 49 50 |
# File 'lib/cybercoach/entry.rb', line 48 def date_modified @date_modified end |
#duration ⇒ Object
:attr: date_modified The date it was modified the last time.
48 49 50 |
# File 'lib/cybercoach/entry.rb', line 48 def duration @duration end |
#location ⇒ Object
:attr: date_modified The date it was modified the last time.
48 49 50 |
# File 'lib/cybercoach/entry.rb', line 48 def location @location end |
#privacy_level ⇒ Object
:attr: date_modified The date it was modified the last time.
48 49 50 |
# File 'lib/cybercoach/entry.rb', line 48 def privacy_level @privacy_level end |
#subscription ⇒ Object
:attr: date_modified The date it was modified the last time.
48 49 50 |
# File 'lib/cybercoach/entry.rb', line 48 def subscription @subscription end |
Instance Method Details
#from_serializable(serializable) ⇒ Object
:category: Serialization
Creates itself from a serializable representation, which only contains simple data types.
- serializable
-
A hash with a single key named like “entry#CyberCoach::Entry.@[email protected]” with another hash as value with the keys:
- uri
-
The URI.
- id
-
The identifier.
- subscription
-
A Subscription serializable.
- comment
-
A comment.
- entrylocation
-
A description of the location.
- entryduration
-
The duration. Nobody knows its unit (seconds/minutes).
- publicvisible
-
The privacy level, see PrivacyLevel constants.
- datecreated
-
The date it was created.
- datemodified
-
The date it was modified the last time.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/cybercoach/entry.rb', line 72 def from_serializable(serializable) # for some reason, the serializable is wrapped another level serializable = serializable.values[0] super(serializable) @subscription = nil unless serializable['subscription'].nil? @subscription = Subscription.new @subscription.from_serializable(serializable['subscription']) end @comment = serializable['comment'] @location = serializable['entrylocation'] @duration = serializable['entryduration'] @privacy_level = serializable['publicvisible'] @date_created = nil unless serializable['datecreated'].nil? @date_created = Time.at(serializable['datecreated']).to_datetime end @date_modified = nil unless serializable['datemodified'].nil? @date_modified = Time.at(serializable['datemodified']).to_datetime end end |
#plural_name ⇒ Object
:category: Configuration
Returns ‘entries’.
140 141 142 |
# File 'lib/cybercoach/entry.rb', line 140 def plural_name 'entries' end |
#resource_base_uri ⇒ Object
:category: Configuration
Return the URI of its subscription.
149 150 151 |
# File 'lib/cybercoach/entry.rb', line 149 def resource_base_uri @subscription.uri end |
#singular_name ⇒ Object
:category: Configuration
Returns ‘entry’.
131 132 133 |
# File 'lib/cybercoach/entry.rb', line 131 def singular_name 'entry' end |
#to_serializable ⇒ Object
:category: Serialization
Returns a serializable representation, which only contains simple data types. The hash has a single key named like “entry#CyberCoach::Entry.@[email protected]” with another hash as value with the keys:
- uri
-
The URI.
- id
-
The identifier.
- comment
-
A comment.
- entrylocation
-
A description of the location.
- entryduration
-
The duration. Nobody knows its unit (seconds/minutes).
- publicvisible
-
The privacy level, see PrivacyLevel constants.
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/cybercoach/entry.rb', line 108 def to_serializable serializable = super serializable['comment'] = @comment serializable['entrylocation'] = @location serializable['entryduration'] = @duration serializable['publicvisible'] = @privacy_level # cyber coach, you cunt! sport = nil if @id.nil? sport = @subscription.uri.split('/')[-1].downcase else sport = @uri.split('/')[-2].downcase end { "#{singular_name}#{sport}" => serializable } end |