Class: TweepList

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title = nil, tags = nil) ⇒ TweepList

Returns a new instance of TweepList.



134
135
136
137
138
139
# File 'lib/tweepml.rb', line 134

def initialize(title=nil, tags=nil)
  @title = title[0..79] unless title.nil?
  @tags = tags
  
  @nodes = []
end

Instance Attribute Details

#tagsObject

Returns the value of attribute tags.



132
133
134
# File 'lib/tweepml.rb', line 132

def tags
  @tags
end

#titleObject

Returns the value of attribute title.



132
133
134
# File 'lib/tweepml.rb', line 132

def title
  @title
end

Instance Method Details

#add_tweep(tweep) ⇒ Object

Add a new Tweep



147
148
149
# File 'lib/tweepml.rb', line 147

def add_tweep(tweep)
  @nodes.push(tweep) unless self.find_by_screen_name(tweep.screen_name)
end

#add_tweep_list(tweep_list) ⇒ Object

Add a nested TweepList



142
143
144
# File 'lib/tweepml.rb', line 142

def add_tweep_list(tweep_list)
  @nodes.push(tweep_list)
end

#find_by_screen_name(screen_name) ⇒ Object

Find a tweep in this list by screen_name



152
153
154
# File 'lib/tweepml.rb', line 152

def find_by_screen_name(screen_name)
  @nodes.select{|t| t.is_a?Tweep and t.screen_name == screen_name}.first
end

#to_xmlObject

XML representation of TweepList



167
168
169
170
171
172
173
174
175
# File 'lib/tweepml.rb', line 167

def to_xml
  tweep_list = Element.new 'tweep_list'
  tweep_list.add_attribute('title', @title) unless @title.nil?
  tweep_list.add_attribute('tags', @tags) unless @tags.nil?
  
  @nodes.each{|n| tweep_list.add_element(n.to_xml)}
  
  tweep_list
end

#tweep_listsObject

List all TweepLists in this list



162
163
164
# File 'lib/tweepml.rb', line 162

def tweep_lists
  @nodes.select{|t| t.is_a?TweepList}
end

#tweepsObject

List all tweeps in this list



157
158
159
# File 'lib/tweepml.rb', line 157

def tweeps
  @nodes.select{|t| t.is_a?Tweep}
end