Class: Atomic::Atom::Person

Inherits:
Object
  • Object
show all
Includes:
Parser
Defined in:
lib/atomic/atom.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Parser

#deserialize, included

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

#emailObject

Returns the value of attribute email.



23
24
25
# File 'lib/atomic/atom.rb', line 23

def email
  @email
end

#nameObject

Returns the value of attribute name.



23
24
25
# File 'lib/atomic/atom.rb', line 23

def name
  @name
end

#typeObject

Returns the value of attribute type.



23
24
25
# File 'lib/atomic/atom.rb', line 23

def type
  @type
end

#uriObject

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_hashObject



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