Class: CyberCoach::Partnership

Inherits:
Resource show all
Includes:
Pageable, PutCreateable
Defined in:
lib/cybercoach/partnership.rb

Overview

A Partnership consists of two Users, which participate in different Sport with Subscriptions, to which Entries are submitted.

Instance Attribute Summary collapse

Attributes inherited from Resource

#id

Attributes inherited from AbstractResource

#uri

Instance Method Summary collapse

Methods included from PutCreateable

included

Methods included from Pageable

included

Methods inherited from Resource

#create, #delete, #update

Methods inherited from AbstractResource

#deserialize, #initialize, #read, #resource_base_uri, #serialize

Constructor Details

This class inherits a constructor from CyberCoach::AbstractResource

Instance Attribute Details

#confirmed_by_proposedObject

:attr: privacy_level The privacy level, see PrivacyLevel constants.



47
48
49
# File 'lib/cybercoach/partnership.rb', line 47

def confirmed_by_proposed
  @confirmed_by_proposed
end

#confirmed_by_proposerObject

:attr: privacy_level The privacy level, see PrivacyLevel constants.



47
48
49
# File 'lib/cybercoach/partnership.rb', line 47

def confirmed_by_proposer
  @confirmed_by_proposer
end

#privacy_levelObject

:attr: privacy_level The privacy level, see PrivacyLevel constants.



47
48
49
# File 'lib/cybercoach/partnership.rb', line 47

def privacy_level
  @privacy_level
end

#proposedObject

:attr: privacy_level The privacy level, see PrivacyLevel constants.



47
48
49
# File 'lib/cybercoach/partnership.rb', line 47

def proposed
  @proposed
end

#proposerObject

:attr: privacy_level The privacy level, see PrivacyLevel constants.



47
48
49
# File 'lib/cybercoach/partnership.rb', line 47

def proposer
  @proposer
end

#subscriptionsObject

:attr: privacy_level The privacy level, see PrivacyLevel constants.



47
48
49
# File 'lib/cybercoach/partnership.rb', line 47

def subscriptions
  @subscriptions
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 the keys:

  • uri

    The URI.

  • id

    The identifier.

  • user1

    A User serializable of the proposer.

  • user2

    A User serializable of the proposed.

  • subscriptions

    Subscription serializables.

  • userconfirmed1

    True if the proposing User has confirmed it, false otherwise.

  • userconfirmed2

    True if the proposed User has confirmed it, false otherwise.

  • publicvisible

    The privacy level, see PrivacyLevel constants.



69
70
71
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/partnership.rb', line 69

def from_serializable(serializable)
  super(serializable)
  @proposer = nil
  unless serializable['user1'].nil?
    @proposer = User.new
    @proposer.from_serializable(serializable['user1'])
  end
  @proposed = nil
  unless serializable['user2'].nil?
    @proposed = User.new
    @proposed.from_serializable(serializable['user2'])
  end
  @subscriptions = []
  unless serializable['subscriptions'].nil?
    @subscriptions = serializable['subscriptions'].map do
    |subscription_serializable|
      subscription = Subscription.new
      subscription.from_serializable(subscription_serializable)
      subscription
    end
  end
  @confirmed_by_proposer = serializable['userconfirmed1']
  @confirmed_by_proposed = serializable['userconfirmed2']
  @privacy_level = serializable['publicvisible']
end

#plural_nameObject

:category: Configuration

Returns ‘partnerships’.



133
134
135
# File 'lib/cybercoach/partnership.rb', line 133

def plural_name
  'partnerships'
end

#singular_nameObject

:category: Configuration

Returns ‘partnership’.



124
125
126
# File 'lib/cybercoach/partnership.rb', line 124

def singular_name
  'partnership'
end

#to_serializableObject

:category: Serialization

Returns a serializable representation, which only contains simple data types. The hash has the keys:

  • uri

    The URI.

  • id

    The identifier.

  • user1

    A User serializable of the proposer.

  • user2

    A User serializable of the proposed.

  • publicvisible

    The privacy level, see PrivacyLevel constants.



107
108
109
110
111
112
113
114
115
116
117
# File 'lib/cybercoach/partnership.rb', line 107

def to_serializable
  serializable = super
  unless @proposer.nil?
    serializable['user1'] = @proposer.to_serializable
  end
  unless @proposed.nil?
    serializable['user2'] = @proposed.to_serializable
  end
  serializable['publicvisible'] = @privacy_level
  serializable
end