Class: Nelumba::Atom::Author
- Inherits:
-
Atom::Person
- Object
- Atom::Person
- Nelumba::Atom::Author
- Includes:
- Atom::SimpleExtensions
- Defined in:
- lib/nelumba/atom/author.rb
Overview
Holds information about the author of the Feed.
Constant Summary collapse
- POCO_NAMESPACE =
The XML namespace the specifies this content.
'http://portablecontacts.net/spec/1.0'
- ACTIVITY_NAMESPACE =
The XML namespace that identifies the conforming specification.
'http://activitystrea.ms/spec/1.0/'
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
-
#activity ⇒ Object
Gives an instance of an Nelumba::Activity that parses the fields having an activity prefix.
-
#initialize(*args) ⇒ Author
constructor
A new instance of Author.
- #to_canonical ⇒ Object
- #to_xml(*args) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Author
Returns a new instance of Author.
81 82 83 84 |
# File 'lib/nelumba/atom/author.rb', line 81 def initialize *args self.activity_object_type = "http://activitystrea.ms/schema/1.0/person" super(*args) end |
Instance Attribute Details
#name ⇒ Object
47 48 49 |
# File 'lib/nelumba/atom/author.rb', line 47 def name @name or self[::Atom::NAMESPACE, 'name'].first end |
#poco_name ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/nelumba/atom/author.rb', line 51 def poco_name return @poco_name if @poco_name name = self[POCO_NAMESPACE, 'name'].first if name name = "<name>#{name}</name>" reader = XML::Reader.string(name) reader.read reader.read Nelumba::Atom::Name.new(reader) else nil end end |
Class Method Details
.from_canonical(obj) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/nelumba/atom/author.rb', line 92 def self.from_canonical(obj) hash = obj.to_hash hash.keys.each do |k| to_k = k if k == :display_name to_k = :displayName elsif k == :preferred_username to_k = :preferredUsername end if k == :extended_name if hash[:extended_name] hash[:"poco_name"] = Nelumba::Atom::Name.new(hash[:extended_name]) end hash.delete :extended_name elsif k == :organization if hash[:organization] hash[:"poco_organization"] = Nelumba::Atom::Organization.new(hash[:organization]) end hash.delete :organization elsif k == :address if hash[:address] hash[:"poco_address"] = Nelumba::Atom::Address.new(hash[:address]) end hash.delete :address elsif k == :account if hash[:account] hash[:"poco_account"] = Nelumba::Atom::Account.new(hash[:account]) end hash.delete :account elsif k == :uid if hash[:uid] hash[:"poco_id"] = hash[:uid] end hash.delete :uid elsif k == :pronoun elsif (k != :uri) && (k != :name) && (k != :email) hash[:"poco_#{to_k}"] = hash[k] hash.delete k end end # Remove any blank entries hash.keys.each do |key| if hash[key].nil? || hash[key] == "" hash.delete key end end self.new(hash) end |
Instance Method Details
#activity ⇒ Object
Gives an instance of an Nelumba::Activity that parses the fields having an activity prefix.
88 89 90 |
# File 'lib/nelumba/atom/author.rb', line 88 def activity Nelumba::Activity.new(self) end |
#to_canonical ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/nelumba/atom/author.rb', line 144 def to_canonical organization = self.poco_organization organization = organization.to_canonical if organization address = self.poco_address address = address.to_canonical if address account = self.poco_account account = account.to_canonical if account ext_name = self.poco_name ext_name = ext_name.to_canonical if ext_name Nelumba::Person.new(:uid => self.poco_id, :extended_name => ext_name, :organization => organization, :address => address, :account => account, :gender => self.poco_gender, :note => self.poco_note, :nickname => self.poco_nickname, :display_name => self.poco_displayName, :preferred_username => self.poco_preferredUsername, :updated => self.poco_updated, :published => self.poco_published, :birthday => self.poco_birthday, :anniversary => self.poco_anniversary, :uri => self.uri, :email => self.email, :name => self.name) end |
#to_xml(*args) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/nelumba/atom/author.rb', line 65 def to_xml(*args) x = super(true) if self.name node = XML::Node.new('name') node << self.name x << node end if self.poco_name x << self.poco_name.to_xml(true, root_name = 'poco:name') end x end |