Class: Nelumba::Person
- Inherits:
-
Object
- Object
- Nelumba::Person
- Defined in:
- lib/nelumba/person.rb
Overview
Holds information about the author of the Feed.
Instance Attribute Summary collapse
-
#account ⇒ Object
readonly
Holds a hash representing information about an account held by this contact.
-
#address ⇒ Object
readonly
Holds a hash representing the address of the contact.
-
#anniversary ⇒ Object
readonly
Holds a DateTime representing a contact’s anniversary.
-
#birthday ⇒ Object
readonly
Holds a DateTime representing this contact’s birthday.
-
#display_name ⇒ Object
readonly
Holds the display name for this contact.
-
#email ⇒ Object
readonly
The email address of the author.
-
#extended_name ⇒ Object
readonly
Holds a hash representing information about the name of this contact.
-
#gender ⇒ Object
readonly
Holds the gender of this contact.
-
#name ⇒ Object
readonly
The name of the author.
-
#nickname ⇒ Object
readonly
Holds the nickname of this contact.
-
#note ⇒ Object
readonly
Holds a note for this contact.
-
#organization ⇒ Object
readonly
Holds a hash representing an organization for this contact.
-
#preferred_username ⇒ Object
readonly
Holds the preferred username of this contact.
-
#pronoun ⇒ Object
readonly
Holds the requested pronouns.
-
#published ⇒ Object
readonly
Holds a DateTime that represents when this contact was originally published.
-
#uid ⇒ Object
readonly
Holds the id that represents this contact.
-
#updated ⇒ Object
readonly
Holds a DateTime that represents when this contact was last modified.
-
#uri ⇒ Object
readonly
The uri that uniquely identifies the author.
Instance Method Summary collapse
-
#act(action, object) ⇒ Object
Creates an Activity where this author acts upon the given object.
-
#favorite(activity) ⇒ Object
Creates an Activity where this author favorites the given activity.
-
#follow(author) ⇒ Object
Creates an Activity where this author follows the given author.
- #init(options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Person
constructor
Creates a representating of an author.
-
#preferred_display_name ⇒ Object
Determines the displayed name to use to refer to this Person.
-
#preferred_short_name ⇒ Object
Determines the short name to use to refer to this Person.
-
#share(activity) ⇒ Object
Creates an Activity where this author shares the given activity.
- #to_as1(*args) ⇒ Object
- #to_atom ⇒ Object
- #to_hash ⇒ Object
-
#to_json(*args) ⇒ Object
Returns a string containing the JSON representation of this Person.
- #to_json_hash ⇒ Object
-
#unfavorite(activity) ⇒ Object
Creates an Activity where this author unfavorites the given activity.
-
#unfollow(author) ⇒ Object
Creates an Activity where this author stops following the given author.
-
#unshare(activity) ⇒ Object
Creates an Activity where this author unshares the given activity.
Constructor Details
#initialize(options = {}) ⇒ Person
Creates a representating of an author.
options:
name => The name of the . 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.
account => A Hash describing the account for the
.
address => A Hash describing the address of the contact.
uri => The uri that uniquely identifies this .
email => The email of the .
138 139 140 |
# File 'lib/nelumba/person.rb', line 138 def initialize( = {}) init() end |
Instance Attribute Details
#account ⇒ Object (readonly)
Holds a hash representing information about an account held by this contact.
contains one or more of the following:
:domain => The top-most domain for this account. (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 @account end |
#address ⇒ Object (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 |
#anniversary ⇒ Object (readonly)
Holds a DateTime representing a contact’s anniversary.
109 110 111 |
# File 'lib/nelumba/person.rb', line 109 def anniversary @anniversary end |
#birthday ⇒ Object (readonly)
Holds a DateTime representing this contact’s birthday.
106 107 108 |
# File 'lib/nelumba/person.rb', line 106 def birthday @birthday end |
#display_name ⇒ Object (readonly)
Holds the display name for this contact.
93 94 95 |
# File 'lib/nelumba/person.rb', line 93 def display_name @display_name end |
#email ⇒ Object (readonly)
The email address of the author.
31 32 33 |
# File 'lib/nelumba/person.rb', line 31 def email @email end |
#extended_name ⇒ Object (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 |
#gender ⇒ Object (readonly)
Holds the gender of this contact.
79 80 81 |
# File 'lib/nelumba/person.rb', line 79 def gender @gender end |
#name ⇒ Object (readonly)
The name of the author
34 35 36 |
# File 'lib/nelumba/person.rb', line 34 def name @name end |
#nickname ⇒ Object (readonly)
Holds the nickname of this contact.
14 15 16 |
# File 'lib/nelumba/person.rb', line 14 def nickname @nickname end |
#note ⇒ Object (readonly)
Holds a note for this contact.
90 91 92 |
# File 'lib/nelumba/person.rb', line 90 def note @note end |
#organization ⇒ Object (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_username ⇒ Object (readonly)
Holds the preferred username of this contact.
96 97 98 |
# File 'lib/nelumba/person.rb', line 96 def preferred_username @preferred_username end |
#pronoun ⇒ Object (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 |
#published ⇒ Object (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 |
#uid ⇒ Object (readonly)
Holds the id that represents this contact.
11 12 13 |
# File 'lib/nelumba/person.rb', line 11 def uid @uid end |
#updated ⇒ Object (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 |
#uri ⇒ Object (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() self.act(, :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( = {}) @uri = [:uri] @name = [:name] || "anonymous" @email = [:email] @uid = [:uid] @name = [:name] @gender = [:gender] @note = [:note] @nickname = [:nickname] @display_name = [:display_name] @preferred_username = [:preferred_username] @updated = [:updated] @published = [:published] @birthday = [:birthday] @anniversary = [:anniversary] @pronoun = [:pronoun] || {} @extended_name = [:extended_name] @organization = [:organization] @account = [:account] @address = [:address] end |
#preferred_display_name ⇒ Object
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_name ⇒ Object
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_atom ⇒ Object
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_hash ⇒ Object
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.account, :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_hash ⇒ Object
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.account, :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() self.act(, :"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 |