class Tweep::Index

Constants

FILE_NAME

Public Class Methods

new() click to toggle source
# File lib/tweep/index.rb, line 10
def initialize
  @states = {}
  @states = YAML::load(File.read(FILE_NAME)) if File.exists?(FILE_NAME)
end

Public Instance Methods

next_retweet_in!(nick, retweeter, wait) click to toggle source
# File lib/tweep/index.rb, line 15
def next_retweet_in!(nick, retweeter, wait)
  ((@states[nick] ||= {})[:waits] ||= {})[retweeter] = wait
end
next_tweet_index(nick) click to toggle source
# File lib/tweep/index.rb, line 19
def next_tweet_index(nick)
  (@states[nick] ||= {})[:next].to_i
end
retweet_timely?(nick, retweeter) click to toggle source
# 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) click to toggle source
# 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!() click to toggle source
# 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.message})"
end
tweeted!(nick, idx) click to toggle source
# File lib/tweep/index.rb, line 38
def tweeted!(nick, idx)
  (@states[nick] ||= {})[:next] = idx + 1
end