Class: Tweep

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(screen_name, id = nil, title = nil, tags = nil) ⇒ Tweep

Create a new Tweep



176
177
178
179
180
181
# File 'lib/tweepml.rb', line 176

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

Instance Attribute Details

#idObject

Returns the value of attribute id.



173
174
175
# File 'lib/tweepml.rb', line 173

def id
  @id
end

#screen_nameObject

Returns the value of attribute screen_name.



173
174
175
# File 'lib/tweepml.rb', line 173

def screen_name
  @screen_name
end

#tagsObject

Returns the value of attribute tags.



173
174
175
# File 'lib/tweepml.rb', line 173

def tags
  @tags
end

#titleObject

Returns the value of attribute title.



173
174
175
# File 'lib/tweepml.rb', line 173

def title
  @title
end

Class Method Details

.find_by_screen_name(screen_name) ⇒ Object

Find a tweep by screen_name



212
213
214
215
216
217
218
219
# File 'lib/tweepml.rb', line 212

def self.find_by_screen_name(screen_name)
  found = nil
  
  ObjectSpace.each_object(Tweep) { |o|
    found = o if o.screen_name == screen_name
  }
  found
end

Instance Method Details

#to_sObject

String representation of a Tweep



195
196
197
# File 'lib/tweepml.rb', line 195

def to_s
  @screen_name
end

#to_xmlObject

XML representation of a Tweep



200
201
202
203
204
205
206
207
208
209
# File 'lib/tweepml.rb', line 200

def to_xml
  tweep = Element.new 'tweep'
  [:id, :screen_name, :title, :tags].each do |prop|
    unless self.send(prop).nil?
      tweep.add_attribute(prop.to_s, "#{self.send(prop)}")
    end
  end
  
  tweep
end