Class: CyberCoach::Entry

Inherits:
Resource show all
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

Attributes inherited from Resource

#id

Attributes inherited from AbstractResource

#uri

Instance Method Summary collapse

Methods included from PostCreateable

included

Methods inherited from Resource

#create, #delete, #update

Methods inherited from AbstractResource

#deserialize, #initialize, #read, #serialize

Constructor Details

This class inherits a constructor from CyberCoach::AbstractResource

Instance Attribute Details

#commentObject

: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_createdObject

: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_modifiedObject

: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

#durationObject

: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

#locationObject

: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_levelObject

: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

#subscriptionObject

: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_nameObject

:category: Configuration

Returns ‘entries’.



140
141
142
# File 'lib/cybercoach/entry.rb', line 140

def plural_name
  'entries'
end

#resource_base_uriObject

: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_nameObject

:category: Configuration

Returns ‘entry’.



131
132
133
# File 'lib/cybercoach/entry.rb', line 131

def singular_name
  'entry'
end

#to_serializableObject

: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