Class: Atomic::Atom::Person
- Inherits:
-
Object
- Object
- Atomic::Atom::Person
- Includes:
- Parser
- Defined in:
- lib/atomic/atom.rb
Instance Attribute Summary collapse
-
#email ⇒ Object
Returns the value of attribute email.
-
#name ⇒ Object
Returns the value of attribute name.
-
#type ⇒ Object
Returns the value of attribute type.
-
#uri ⇒ Object
Returns the value of attribute uri.
Instance Method Summary collapse
- #handle_close_element(node) ⇒ Object
- #handle_open_element(node, reader) ⇒ Object
-
#initialize(params = {}) ⇒ Person
constructor
A new instance of Person.
- #to_hash ⇒ Object
- #to_xml(as_document = true, target = nil) ⇒ Object
Methods included from Parser
Constructor Details
#initialize(params = {}) ⇒ Person
Returns a new instance of Person.
25 26 27 28 29 30 31 32 |
# File 'lib/atomic/atom.rb', line 25 def initialize(params = {}) params.symbolize_keys! params.assert_valid_keys(:type, :name, :uri, :email) self.type = params[:type] self.name = params[:name] self.uri = params[:uri] self.email = params[:email] end |
Instance Attribute Details
#email ⇒ Object
Returns the value of attribute email.
23 24 25 |
# File 'lib/atomic/atom.rb', line 23 def email @email end |
#name ⇒ Object
Returns the value of attribute name.
23 24 25 |
# File 'lib/atomic/atom.rb', line 23 def name @name end |
#type ⇒ Object
Returns the value of attribute type.
23 24 25 |
# File 'lib/atomic/atom.rb', line 23 def type @type end |
#uri ⇒ Object
Returns the value of attribute uri.
23 24 25 |
# File 'lib/atomic/atom.rb', line 23 def uri @uri end |
Instance Method Details
#handle_close_element(node) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/atomic/atom.rb', line 48 def handle_close_element(node) case [node.depth, node.uri, node.name] when [0, NS_ATOM, 'author'] self.type = 'author' when [0, NS_ATOM, 'contributor'] self.type = 'contributor' when [1, NS_ATOM, 'name'] self.name = node.text when [1, NS_ATOM, 'uri'] self.uri = node.text when [1, NS_ATOM, 'email'] self.email = node.text else puts("Person ==> Unexpected Close Element - [#{node.depth}] #{node.name} #{node.uri} #{node.attributes.inspect} #{node.text}") end end |
#handle_open_element(node, reader) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/atomic/atom.rb', line 34 def handle_open_element(node, reader) progressed = false case [node.depth, node.uri, node.name] when [0, NS_ATOM, 'author'] when [0, NS_ATOM, 'contributor'] when [1, NS_ATOM, 'name'] when [1, NS_ATOM, 'uri'] when [1, NS_ATOM, 'email'] else puts("Person ==> Unexpected Open Element - [#{node.depth}] #{node.name} #{node.uri} #{node.attributes.inspect}") end return progressed end |
#to_hash ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/atomic/atom.rb', line 65 def to_hash { :type => self.type, :name => self.name, :uri => self.uri, :email => self.email } end |
#to_xml(as_document = true, target = nil) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/atomic/atom.rb', line 74 def to_xml(as_document=true, target=nil) nsdec = as_document ? {:"xmlns:atom" => NS_ATOM} : {} xml = Builder::XmlMarkup.new(:target => target) xml.instruct! if as_document xml.atom(type.to_sym, nsdec) do xml.atom(:name, self.name) xml.atom(:uri, self.uri) xml.atom(:email, self.email) end xml.target! end |