Class: Tweep::Config

Inherits:
Object show all
Defined in:
lib/tweep/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, index) ⇒ Config

Returns a new instance of Config.



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/tweep/config.rb', line 12

def initialize(file, index)
  config = YAML::load(File.read(file))

  @nick = File.basename(file, '.*')
  @index = index
  
  load_auth config
  load_schedule config
  load_retweeters config

  @tweets = (config['tweets'] || []).map(&:strip)
end

Instance Attribute Details

#authObject (readonly)

Returns the value of attribute auth.



10
11
12
# File 'lib/tweep/config.rb', line 10

def auth
  @auth
end

#nickObject (readonly)

Returns the value of attribute nick.



10
11
12
# File 'lib/tweep/config.rb', line 10

def nick
  @nick
end

#retweetersObject (readonly)

Returns the value of attribute retweeters.



10
11
12
# File 'lib/tweep/config.rb', line 10

def retweeters
  @retweeters
end

#scheduleObject (readonly)

Returns the value of attribute schedule.



10
11
12
# File 'lib/tweep/config.rb', line 10

def schedule
  @schedule
end

#tweetsObject (readonly)

Returns the value of attribute tweets.



10
11
12
# File 'lib/tweep/config.rb', line 10

def tweets
  @tweets
end

Instance Method Details

#has_auth?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/tweep/config.rb', line 25

def has_auth?
  4 == @auth.values.reject(&:blank?).size
end

#has_tweets?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/tweep/config.rb', line 29

def has_tweets?
  @tweets.any?
end

#next_tweetObject



33
34
35
36
37
# File 'lib/tweep/config.rb', line 33

def next_tweet
  idx = @index.next_tweet_index(@nick)
  idx = 0 if idx.to_i >= @tweets.size
  [@tweets[idx], idx]
end

#now_is_a_good_time?Boolean

Returns:

  • (Boolean)


39
40
41
42
43
44
45
# File 'lib/tweep/config.rb', line 39

def now_is_a_good_time?
  now = Time.now
  (0..@allowed_delay.to_i).any? do |offset|
    time = now - offset * 60
    (@schedule[time.wday] || []).include?(time.strftime('%H:%M'))
  end
end

#should_get_retweeted_by?(retweeter) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
50
51
52
53
54
# File 'lib/tweep/config.rb', line 47

def should_get_retweeted_by?(retweeter)
  if (result = @index.retweet_timely?(@nick, retweeter))
    @index.next_retweet_in! @nick, retweeter, @retweeters[retweeter]
  else
    @index.retweet_will_wait! @nick, retweeter
  end
  result
end