Class: FakeTwitter::TweetFactory
- Inherits:
-
Object
- Object
- FakeTwitter::TweetFactory
- Defined in:
- lib/faketwitter.rb
Constant Summary collapse
- DEFAULTS =
{ "text"=>"just some tweet", "from_user"=>"jojo", "to_user_id"=>nil, "iso_language_code"=>"en", "source"=>'<a href="http://twitter.com/">web</a>', }
Class Method Summary collapse
- .counter(counter_type) ⇒ Object
- .create(attributes) ⇒ Object
- .reset ⇒ Object
- .user_id_for(user) ⇒ Object
Class Method Details
.counter(counter_type) ⇒ Object
104 105 106 107 |
# File 'lib/faketwitter.rb', line 104 def counter(counter_type) @counter ||= Hash.new(0) @counter[counter_type] += 1 end |
.create(attributes) ⇒ Object
94 95 96 97 98 99 100 101 102 |
# File 'lib/faketwitter.rb', line 94 def create(attributes) tweet = DEFAULTS.merge(attributes.stringify_keys) tweet['id'] ||= counter(:id) tweet['from_user_id'] ||= user_id_for(tweet['from_user']) tweet['profile_image_url'] ||= "http://s3.amazonaws.com/twitter_production/profile_images/#{tweet['from_user_id']}/photo.jpg" tweet['created_at'] ||= Time.now tweet end |
.reset ⇒ Object
89 90 91 92 |
# File 'lib/faketwitter.rb', line 89 def reset @counter = nil @users = nil end |
.user_id_for(user) ⇒ Object
109 110 111 112 |
# File 'lib/faketwitter.rb', line 109 def user_id_for(user) @users ||= {} @users[user] ||= counter(:user_id) end |