class CyberCoach::Entry

An Entry is submitted to a Subscription to represent a finished activity of a specific duration at a specific location.

Attributes

comment[RW]

A comment.

date_created[RW]

The date it was created.

date_modified[RW]

:attr: date_modified The date it was modified the last time.

duration[RW]

The duration. Nobody knows its unit (seconds/minutes).

location[RW]

A description of the location.

privacy_level[RW]

The privacy level, see PrivacyLevel constants.

subscription[RW]

The Subscription it belongs to.

Protected Instance Methods

initializable_with() click to toggle source
Calls superclass method
# File lib/cybercoach/entry.rb, line 166
def initializable_with
  super + [:subscription, :comment, :location, :duration, :privacy_level]
end

Configuration

↑ top

Public Instance Methods

plural_name() click to toggle source

Returns ‘entries’.

# File lib/cybercoach/entry.rb, line 140
def plural_name
  'entries'
end
resource_base_uri() click to toggle source

Return the URI of its subscription.

# File lib/cybercoach/entry.rb, line 149
def resource_base_uri
  @subscription.uri
end
singular_name() click to toggle source

Returns ‘entry’.

# File lib/cybercoach/entry.rb, line 131
def singular_name
  'entry'
end

Invalidation

↑ top

Protected Instance Methods

invalidate_uri() click to toggle source

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

↑ top

Public Instance Methods

from_serializable(serializable) click to toggle source

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.

Calls superclass method
# 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
to_serializable() click to toggle source

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.

Calls superclass method
# 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