Class: TweepML

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source = nil) ⇒ TweepML

Create a new TweepML representation.

Optional parameter of a string to parse



17
18
19
20
# File 'lib/tweepml.rb', line 17

def initialize(source=nil)
  @tweep_list = TweepList.new
  parse(source) if source
end

Instance Attribute Details

#contact_nameObject

Returns the value of attribute contact_name.



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

def contact_name
  @contact_name
end

#contact_screen_nameObject

Returns the value of attribute contact_screen_name.



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

def contact_screen_name
  @contact_screen_name
end

Returns the value of attribute copyright.



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

def copyright
  @copyright
end

#date_createdObject

Returns the value of attribute date_created.



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

def date_created
  @date_created
end

#date_modifiedObject

Returns the value of attribute date_modified.



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

def date_modified
  @date_modified
end

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

#error_codeObject

Returns the value of attribute error_code.



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

def error_code
  @error_code
end

#error_descriptionObject

Returns the value of attribute error_description.



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

def error_description
  @error_description
end

#generatorObject

Returns the value of attribute generator.



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

def generator
  @generator
end

Returns the value of attribute generator_link.



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

def generator_link
  @generator_link
end

Returns the value of attribute link.



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

def link
  @link
end

#tagsObject

Returns the value of attribute tags.



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

def tags
  @tags
end

#titleObject

Returns the value of attribute title.



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

def title
  @title
end

#tweep_listObject

Returns the value of attribute tweep_list.



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

def tweep_list
  @tweep_list
end

Instance Method Details

#to_xmlObject

XML representation of the TweepML



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/tweepml.rb', line 53

def to_xml
  doc = Document.new
  tml = doc.add_element 'tweepml', {'version' => '1.0'}
  
  # Add the header elements
  head = tml.add_element 'head'
  [:title, :description, :link, :date_created, :date_modified, :contact_name, :contact_screen_name,
  :copyright, :error_code, :error_description, :tags].each do |prop|
    unless self.send(prop).nil?
      t = head.add_element prop.to_s
      t.text = self.send(prop)
    end
  end
  
  head.add_element("generator").text = "TweepML Ruby Generator v0.1"
  head.add_element("generator_link").text = "http://github.com/dacort/tweepml"
  
  # Add the tweep_list element
  tweep_list = tml.add_element 'tweep_list'
  
  # Iterate through all tweeps/tweep_lists - should probably use nodes
  self.tweep_list.tweep_lists.each do|tl|
    tweep_list.add_element(tl.to_xml)
  end
  
  doc
end