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.



128
129
130
131
132
133
# File 'lib/tweepml.rb', line 128

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.



126
127
128
# File 'lib/tweepml.rb', line 126

def tags
  @tags
end

#titleObject

Returns the value of attribute title.



126
127
128
# File 'lib/tweepml.rb', line 126

def title
  @title
end

Instance Method Details

#add_tweep(tweep) ⇒ Object

Add a new Tweep



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

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



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

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



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

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



161
162
163
164
165
166
167
168
169
# File 'lib/tweepml.rb', line 161

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



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

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

#tweepsObject

List all tweeps in this list



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

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