Class: Cinch::Plugins::TwitterWatch::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/cinch/plugins/twitterwatch/cache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nick, channel, client) ⇒ Cache

Returns a new instance of Cache.



6
7
8
9
10
11
# File 'lib/cinch/plugins/twitterwatch/cache.rb', line 6

def initialize(nick, channel, client)
  @nick = nick
  @client = client
  @channel = channel
  @tweet_cache = {}
end

Instance Attribute Details

#channelObject

Returns the value of attribute channel.



4
5
6
# File 'lib/cinch/plugins/twitterwatch/cache.rb', line 4

def channel
  @channel
end

#clientObject

Returns the value of attribute client.



4
5
6
# File 'lib/cinch/plugins/twitterwatch/cache.rb', line 4

def client
  @client
end

#nickObject

Returns the value of attribute nick.



4
5
6
# File 'lib/cinch/plugins/twitterwatch/cache.rb', line 4

def nick
  @nick
end

#tweet_cacheObject

Returns the value of attribute tweet_cache.



4
5
6
# File 'lib/cinch/plugins/twitterwatch/cache.rb', line 4

def tweet_cache
  @tweet_cache
end

Instance Method Details

#cache_tweet(tweet_id) ⇒ Object



29
30
31
32
# File 'lib/cinch/plugins/twitterwatch/cache.rb', line 29

def cache_tweet(tweet_id)
  @tweet_cache[tweet_id.to_i] = true
  true
end

#init_cacheObject



13
14
15
16
17
18
19
20
21
# File 'lib/cinch/plugins/twitterwatch/cache.rb', line 13

def init_cache
  @client.user_timeline(@nick).each do |tweet|
    cache_tweet(tweet.id)
  end
  "Cache: [#{@nick}]: #{@tweet_cache.count} tweets cached."
rescue Twitter::Error::NotFound
  debug "You have set an invalid or protected user (#{@nick}) to " +
        ' watch, please correct this error'
end

#tweet_unless_cached(tweet_id) ⇒ Object



23
24
25
26
27
# File 'lib/cinch/plugins/twitterwatch/cache.rb', line 23

def tweet_unless_cached(tweet_id)
  return if @tweet_cache.key?(tweet_id)
  cache_tweet(tweet_id)
  @client.status(tweet_id).text
end