Class: MurmuringSpider::Status

Inherits:
Object
  • Object
show all
Includes:
DataMapper::Resource
Defined in:
lib/murmuring_spider/status.rb

Constant Summary collapse

@@extended_fields =
{}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(s) ⇒ Status

Returns a new instance of Status.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/murmuring_spider/status.rb', line 51

def initialize(s)
  values = {}
  @@extended_fields.each do |field, func|
    if func
      values[field] = func.call(s)
    else
      values[field] = s.__send__(field)
    end
  end
  super(:tweet_id => s.id,
      :text => s.url_expanded_text,
      :user_id => s.user ? s.user.id : s.from_user_id,
      :screen_name => s.user ? s.user.screen_name : s.from_user,
      :created_at => s.created_at,
      :extended => values)
end

Class Method Details

.extend(field, &b) ⇒ Object

extend fields You can save a parameter of status which is not supported by default If block given, initializer gives the Twitter::Status object to it, and the result of the given block is used as the field value

  • field : field name. String or Symbol is expected. Twitter::Status should have the same name method.

  • _&b_ : block to get the field value from Twitter::Status object.



43
44
45
46
47
48
# File 'lib/murmuring_spider/status.rb', line 43

def extend(field, &b)
  @@extended_fields[field] = b
  define_method(field.to_s) do
    extended[field]
  end
end