Class: Nelumba::Person

Inherits:
Object
  • Object
show all
Defined in:
lib/nelumba/person.rb

Overview

Holds information about the author of the Feed.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Person

Creates a representating of an author.

options:

name               => The name of the author. Defaults: "anonymous"
uid                => The identifier that uniquely identifies the
                      contact.
nickname           => The nickname of the contact.
gender             => The gender of the contact.
note               => A note for this contact.
display_name       => The display name for this contact.
preferred_username => The preferred username for this contact.
updated            => A DateTime representing when this contact was
                      last updated.
published          => A DateTime representing when this contact was
                      originally created.
birthday           => A DateTime representing a birthday for this
                      contact.
anniversary        => A DateTime representing an anniversary for this
                      contact.
extended_name      => A Hash representing the name of the contact.
organization       => A Hash representing the organization of which the
                      contact belongs.
            => A Hash describing the authorative  for the
                      author.
address            => A Hash describing the address of the contact.
uri                => The uri that uniquely identifies this author.
email              => The email of the author.


138
139
140
# File 'lib/nelumba/person.rb', line 138

def initialize(options = {})
  init(options)
end

Instance Attribute Details

#accountObject (readonly)

Holds a hash representing information about an account held by this contact.

contains one or more of the following:

:domain   => The top-most authoriative domain for this . (e.g.
             "twitter.com") This is the primary field. Is required.
             Used for sorting.
:username => An alphanumeric username, typically chosen by the user.
:userid   => A user id, typically assigned, that uniquely refers to
             the user.


76
77
78
# File 'lib/nelumba/person.rb', line 76

def 
  @account
end

#addressObject (readonly)

Holds a hash representing the address of the contact.

contains one or more of the following:

:formatted      => A formatted representating of the address. May
                  contain newlines.
:street_address => The full street address. May contain newlines.
:locality       => The city or locality component.
:region         => The state or region component.
:postal_code    => The zipcode or postal code component.
:country        => The country name component.


46
47
48
# File 'lib/nelumba/person.rb', line 46

def address
  @address
end

#anniversaryObject (readonly)

Holds a DateTime representing a contact’s anniversary.



109
110
111
# File 'lib/nelumba/person.rb', line 109

def anniversary
  @anniversary
end

#birthdayObject (readonly)

Holds a DateTime representing this contact’s birthday.



106
107
108
# File 'lib/nelumba/person.rb', line 106

def birthday
  @birthday
end

#display_nameObject (readonly)

Holds the display name for this contact.



93
94
95
# File 'lib/nelumba/person.rb', line 93

def display_name
  @display_name
end

#emailObject (readonly)

The email address of the author.



31
32
33
# File 'lib/nelumba/person.rb', line 31

def email
  @email
end

#extended_nameObject (readonly)

Holds a hash representing information about the name of this contact.

contains one or more of the following:

:formatted         => The full name of the contact
:family_name       => The family name. "Last name" in Western contexts.
:given_name        => The given name. "First name" in Western contexts.
:middle_name       => The middle name.
:honorific_prefix  => "Title" in Western contexts. (e.g. "Mr." "Mrs.")
:honorific_suffix  => "Suffix" in Western contexts. (e.g. "Esq.")


25
26
27
# File 'lib/nelumba/person.rb', line 25

def extended_name
  @extended_name
end

#genderObject (readonly)

Holds the gender of this contact.



79
80
81
# File 'lib/nelumba/person.rb', line 79

def gender
  @gender
end

#nameObject (readonly)

The name of the author



34
35
36
# File 'lib/nelumba/person.rb', line 34

def name
  @name
end

#nicknameObject (readonly)

Holds the nickname of this contact.



14
15
16
# File 'lib/nelumba/person.rb', line 14

def nickname
  @nickname
end

#noteObject (readonly)

Holds a note for this contact.



90
91
92
# File 'lib/nelumba/person.rb', line 90

def note
  @note
end

#organizationObject (readonly)

Holds a hash representing an organization for this contact.

contains one or more of the following:

:name        => The name of the organization (e.g. company, school,
                etc) This field is required. Will be used for sorting.
:department  => The department within the organization.
:title       => The title or role within the organization.
:type        => The type of organization. Canonical values include
                "job" or "school"
:start_date  => A DateTime representing when the contact joined
                the organization.
:end_date    => A DateTime representing when the contact left the
                organization.
:location    => The physical location of this organization.
:description => A free-text description of the role this contact
                played in this organization.


64
65
66
# File 'lib/nelumba/person.rb', line 64

def organization
  @organization
end

#preferred_usernameObject (readonly)

Holds the preferred username of this contact.



96
97
98
# File 'lib/nelumba/person.rb', line 96

def preferred_username
  @preferred_username
end

#pronounObject (readonly)

Holds the requested pronouns.

contains one or more of the following:

:plural     => Whether or not the actor is considered plural
:personal   => Personal pronoun (xe)
:possessive => Possessive pronoun (her)


87
88
89
# File 'lib/nelumba/person.rb', line 87

def pronoun
  @pronoun
end

#publishedObject (readonly)

Holds a DateTime that represents when this contact was originally published.



103
104
105
# File 'lib/nelumba/person.rb', line 103

def published
  @published
end

#uidObject (readonly)

Holds the id that represents this contact.



11
12
13
# File 'lib/nelumba/person.rb', line 11

def uid
  @uid
end

#updatedObject (readonly)

Holds a DateTime that represents when this contact was last modified.



99
100
101
# File 'lib/nelumba/person.rb', line 99

def updated
  @updated
end

#uriObject (readonly)

The uri that uniquely identifies the author.



28
29
30
# File 'lib/nelumba/person.rb', line 28

def uri
  @uri
end

Instance Method Details

#act(action, object) ⇒ Object

Creates an Activity where this author acts upon the given object.



221
222
223
224
225
226
227
228
229
# File 'lib/nelumba/person.rb', line 221

def act(action, object)
  type = "person"
  type = object.type if object.is_a? Nelumba::Activity

  Nelumba::Activity.new :verb   => action,
                        :actor  => self,
                        :object => object,
                        :type   => type
end

#favorite(activity) ⇒ Object

Creates an Activity where this author favorites the given activity.



232
233
234
# File 'lib/nelumba/person.rb', line 232

def favorite(activity)
  self.act(activity, :favorite)
end

#follow(author) ⇒ Object

Creates an Activity where this author follows the given author.



252
253
254
# File 'lib/nelumba/person.rb', line 252

def follow(author)
  self.act(author, :follow)
end

#init(options = {}) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/nelumba/person.rb', line 142

def init(options = {})
  @uri                = options[:uri]
  @name               = options[:name] || "anonymous"
  @email              = options[:email]

  @uid                = options[:uid]
  @name               = options[:name]
  @gender             = options[:gender]
  @note               = options[:note]
  @nickname           = options[:nickname]
  @display_name       = options[:display_name]
  @preferred_username = options[:preferred_username]
  @updated            = options[:updated]
  @published          = options[:published]
  @birthday           = options[:birthday]
  @anniversary        = options[:anniversary]

  @pronoun            = options[:pronoun] || {}

  @extended_name      = options[:extended_name]
  @organization       = options[:organization]
  @account            = options[:account]
  @address            = options[:address]
end

#preferred_display_nameObject

Determines the displayed name to use to refer to this Person.



262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/nelumba/person.rb', line 262

def preferred_display_name
  if self.display_name
    self.display_name
  elsif self.name
    self.name
  elsif self.preferred_username
    self.preferred_username
  elsif self.nickname
    self.nickname
  else
    self.uid
  end
end

#preferred_short_nameObject

Determines the short name to use to refer to this Person.



277
278
279
280
281
282
283
284
285
286
287
288
289
# File 'lib/nelumba/person.rb', line 277

def preferred_short_name
  if self.preferred_username
    self.preferred_username
  elsif self.nickname
    self.nickname
  elsif self.display_name
    self.display_name
  elsif self.name
    self.name
  else
    self.uid
  end
end

#share(activity) ⇒ Object

Creates an Activity where this author shares the given activity.



242
243
244
# File 'lib/nelumba/person.rb', line 242

def share(activity)
  self.act(activity, :share)
end

#to_as1(*args) ⇒ Object



296
297
298
# File 'lib/nelumba/person.rb', line 296

def to_as1(*args)
  to_json_hash.delete_if{|k,v| v.nil?}.to_json(*args)
end

#to_atomObject



300
301
302
303
304
# File 'lib/nelumba/person.rb', line 300

def to_atom
  require 'nelumba/atom/person'

  Nelumba::Atom::Person.from_canonical(self).to_xml
end

#to_hashObject



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/nelumba/person.rb', line 167

def to_hash
  {
    :uri                => self.uri,
    :email              => self.email,
    :name               => self.name,

    :uid                => self.uid,
    :gender             => self.gender,
    :note               => self.note,
    :nickname           => self.nickname,
    :display_name       => self.display_name,
    :preferred_username => self.preferred_username,
    :updated            => self.updated,
    :published          => self.published,
    :birthday           => self.birthday,
    :anniversary        => self.anniversary,

    :pronoun            => self.pronoun,

    :extended_name      => self.extended_name,
    :organization       => self.organization,
    :account            => self.,
    :address            => self.address
  }
end

#to_json(*args) ⇒ Object

Returns a string containing the JSON representation of this Person.



292
293
294
# File 'lib/nelumba/person.rb', line 292

def to_json(*args)
  to_json_hash.delete_if{|k,v| v.nil?}.to_json(*args)
end

#to_json_hashObject



193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/nelumba/person.rb', line 193

def to_json_hash
  {
    :uri               => self.uri,
    :email             => self.email,
    :name              => self.name,
    :objectType        => "person",

    :id                => self.uid,
    :gender            => self.gender,
    :note              => self.note,
    :nickname          => self.nickname,
    :displayName       => self.display_name,
    :preferredUsername => self.preferred_username,
    :updated           => self.updated,
    :published         => self.published,
    :birthday          => self.birthday,
    :anniversary       => self.anniversary,

    :pronoun           => self.pronoun,

    :extendedName      => self.extended_name,
    :organization      => self.organization,
    :account           => self.,
    :address           => self.address
  }
end

#unfavorite(activity) ⇒ Object

Creates an Activity where this author unfavorites the given activity.



237
238
239
# File 'lib/nelumba/person.rb', line 237

def unfavorite(activity)
  self.act(activity, :unfavorite)
end

#unfollow(author) ⇒ Object

Creates an Activity where this author stops following the given author.



257
258
259
# File 'lib/nelumba/person.rb', line 257

def unfollow(author)
  self.act(author, :"stop-following")
end

#unshare(activity) ⇒ Object

Creates an Activity where this author unshares the given activity.



247
248
249
# File 'lib/nelumba/person.rb', line 247

def unshare(activity)
  self.act(activity, :unshare)
end