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



182
183
184
185
186
187
# File 'lib/tweepml.rb', line 182

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.



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

def id
  @id
end

#screen_nameObject

Returns the value of attribute screen_name.



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

def screen_name
  @screen_name
end

#tagsObject

Returns the value of attribute tags.



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

def tags
  @tags
end

#titleObject

Returns the value of attribute title.



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

def title
  @title
end

Class Method Details

.find_by_screen_name(screen_name) ⇒ Object

Find a tweep by screen_name



218
219
220
221
222
223
224
225
# File 'lib/tweepml.rb', line 218

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



201
202
203
# File 'lib/tweepml.rb', line 201

def to_s
  @screen_name
end

#to_xmlObject

XML representation of a Tweep



206
207
208
209
210
211
212
213
214
215
# File 'lib/tweepml.rb', line 206

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