Class: Tweep::Index
Constant Summary collapse
- FILE_NAME =
'tweeping.idx'
Instance Method Summary collapse
-
#initialize ⇒ Index
constructor
A new instance of Index.
- #next_retweet_in!(nick, retweeter, wait) ⇒ Object
- #next_tweet_index(nick) ⇒ Object
- #retweet_timely?(nick, retweeter) ⇒ Boolean
- #retweet_will_wait!(nick, retweeter) ⇒ Object
- #save! ⇒ Object
- #tweeted!(nick, idx) ⇒ Object
Constructor Details
Instance Method Details
#next_retweet_in!(nick, retweeter, wait) ⇒ Object
15 16 17 |
# File 'lib/tweep/index.rb', line 15 def next_retweet_in!(nick, retweeter, wait) ((@states[nick] ||= {})[:waits] ||= {})[retweeter] = wait end |
#next_tweet_index(nick) ⇒ Object
19 20 21 |
# File 'lib/tweep/index.rb', line 19 def next_tweet_index(nick) (@states[nick] ||= {})[:next].to_i end |
#retweet_timely?(nick, retweeter) ⇒ Boolean
23 24 25 |
# File 'lib/tweep/index.rb', line 23 def retweet_timely?(nick, retweeter) ((@states[nick] ||= {})[:waits] ||= {})[retweeter].to_i.zero? end |
#retweet_will_wait!(nick, retweeter) ⇒ Object
27 28 29 30 |
# File 'lib/tweep/index.rb', line 27 def retweet_will_wait!(nick, retweeter) wait = ((@states[nick] ||= {})[:waits] ||= {})[retweeter].to_i @states[nick][:waits][retweeter] = [wait - 1, 0].max end |
#save! ⇒ Object
32 33 34 35 36 |
# File 'lib/tweep/index.rb', line 32 def save! File.open(FILE_NAME, 'w') { |f| f.write(YAML::dump(@states)) } rescue Exception => e Tweep.error "Could not save index to #{FILE_NAME} (#{e.class.name}: #{e.})" end |
#tweeted!(nick, idx) ⇒ Object
38 39 40 |
# File 'lib/tweep/index.rb', line 38 def tweeted!(nick, idx) (@states[nick] ||= {})[:next] = idx + 1 end |