class CyberCoach::Entry
An Entry
is submitted to a Subscription
to represent a finished activity of a specific duration at a specific location.
Attributes
A comment.
The date it was created.
:attr: date_modified
The date it was modified the last time.
The duration. Nobody knows its unit (seconds/minutes).
A description of the location.
The privacy level, see PrivacyLevel
constants.
The Subscription
it belongs to.
Protected Instance Methods
# File lib/cybercoach/entry.rb, line 166 def initializable_with super + [:subscription, :comment, :location, :duration, :privacy_level] end
Configuration
↑ topPublic Instance Methods
Returns ‘entries’.
# File lib/cybercoach/entry.rb, line 140 def plural_name 'entries' end
Return the URI of its subscription.
# File lib/cybercoach/entry.rb, line 149 def resource_base_uri @subscription.uri end
Returns ‘entry’.
# File lib/cybercoach/entry.rb, line 131 def singular_name 'entry' end
Invalidation
↑ topProtected Instance Methods
Sets the uri to the base uri and the id, if it is not nil.
# File lib/cybercoach/entry.rb, line 160 def invalidate_uri unless @id.nil? @uri = "#{resource_base_uri}#{@id}/" end end
Serialization
↑ topPublic Instance Methods
Creates itself from a serializable representation, which only contains simple data types.
- serializable
-
A hash with a single key named like “entry#{@sport.name}” 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.
# 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
Returns a serializable representation, which only contains simple data types. The hash has a single key named like “entry#{@sport.name}” 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.
# 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