Class: Tweep::Config
Instance Attribute Summary collapse
-
#auth ⇒ Object
readonly
Returns the value of attribute auth.
-
#nick ⇒ Object
readonly
Returns the value of attribute nick.
-
#retweeters ⇒ Object
readonly
Returns the value of attribute retweeters.
-
#schedule ⇒ Object
readonly
Returns the value of attribute schedule.
-
#tweets ⇒ Object
readonly
Returns the value of attribute tweets.
Instance Method Summary collapse
- #has_auth? ⇒ Boolean
- #has_tweets? ⇒ Boolean
-
#initialize(file, index) ⇒ Config
constructor
A new instance of Config.
- #next_tweet ⇒ Object
- #now_is_a_good_time? ⇒ Boolean
- #should_get_retweeted_by?(retweeter) ⇒ Boolean
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
#auth ⇒ Object (readonly)
Returns the value of attribute auth.
10 11 12 |
# File 'lib/tweep/config.rb', line 10 def auth @auth end |
#nick ⇒ Object (readonly)
Returns the value of attribute nick.
10 11 12 |
# File 'lib/tweep/config.rb', line 10 def nick @nick end |
#retweeters ⇒ Object (readonly)
Returns the value of attribute retweeters.
10 11 12 |
# File 'lib/tweep/config.rb', line 10 def retweeters @retweeters end |
#schedule ⇒ Object (readonly)
Returns the value of attribute schedule.
10 11 12 |
# File 'lib/tweep/config.rb', line 10 def schedule @schedule end |
#tweets ⇒ Object (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
25 26 27 |
# File 'lib/tweep/config.rb', line 25 def has_auth? 4 == @auth.values.reject(&:blank?).size end |
#has_tweets? ⇒ Boolean
29 30 31 |
# File 'lib/tweep/config.rb', line 29 def has_tweets? @tweets.any? end |
#next_tweet ⇒ Object
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
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
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 |