Class: TweetWatch::Config
- Inherits:
-
Object
- Object
- TweetWatch::Config
- Defined in:
- lib/tweet_watch/config.rb
Instance Attribute Summary collapse
-
#accounts ⇒ Object
Returns the value of attribute accounts.
-
#count ⇒ Object
Returns the value of attribute count.
-
#error_message ⇒ Object
readonly
Returns the value of attribute error_message.
-
#path ⇒ Object
Returns the value of attribute path.
-
#tweeters ⇒ Object
Returns the value of attribute tweeters.
Instance Method Summary collapse
- #get_account(screen_name = nil) ⇒ Object
- #has_tweeter?(tweeter) ⇒ Boolean
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #load_from_path(path) ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
7 8 9 10 11 12 |
# File 'lib/tweet_watch/config.rb', line 7 def initialize @accounts = [] @tweeters = [] @count = 50 @error_message = "" end |
Instance Attribute Details
#accounts ⇒ Object
Returns the value of attribute accounts.
3 4 5 |
# File 'lib/tweet_watch/config.rb', line 3 def accounts @accounts end |
#count ⇒ Object
Returns the value of attribute count.
3 4 5 |
# File 'lib/tweet_watch/config.rb', line 3 def count @count end |
#error_message ⇒ Object (readonly)
Returns the value of attribute error_message.
5 6 7 |
# File 'lib/tweet_watch/config.rb', line 5 def @error_message end |
#path ⇒ Object
Returns the value of attribute path.
3 4 5 |
# File 'lib/tweet_watch/config.rb', line 3 def path @path end |
#tweeters ⇒ Object
Returns the value of attribute tweeters.
3 4 5 |
# File 'lib/tweet_watch/config.rb', line 3 def tweeters @tweeters end |
Instance Method Details
#get_account(screen_name = nil) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/tweet_watch/config.rb', line 50 def get_account(screen_name = nil) account = @accounts.first unless screen_name.nil? res = @accounts.select { |u| u.screen_name.strip() == screen_name.strip() } account = res.first if res.size > 0 end return account end |
#has_tweeter?(tweeter) ⇒ Boolean
39 40 41 42 |
# File 'lib/tweet_watch/config.rb', line 39 def has_tweeter?(tweeter) res = @tweeters.find{|t| t.downcase.strip == tweeter.downcase.strip } res != nil end |
#load_from_path(path) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/tweet_watch/config.rb', line 14 def load_from_path(path) unless File.exist?(path) raise ArgumentError.new("The provided config file could not be located: #{path}") end @path = path c = YAML.load_file(@path) unless c["accounts"].nil? c["accounts"].each do |f| self.accounts << Account.new(f["screen_name"], f["consumer_key"], f["consumer_secret"], f["access_token"], f["access_token_secret"]) end end unless c["tweeters"].nil? c["tweeters"].each do |t| self.tweeters << t unless has_tweeter?(t) end end self end |
#valid? ⇒ Boolean
44 45 46 47 48 |
# File 'lib/tweet_watch/config.rb', line 44 def valid? @error_message = "" @error_message += "There should be at least one account" if accounts.size ==0 @error_message.strip().length == 0 end |