Class: TweetWatch::Config

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

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

#accountsObject

Returns the value of attribute accounts.



3
4
5
# File 'lib/tweet_watch/config.rb', line 3

def accounts
  @accounts
end

#countObject

Returns the value of attribute count.



3
4
5
# File 'lib/tweet_watch/config.rb', line 3

def count
  @count
end

#error_messageObject (readonly)

Returns the value of attribute error_message.



5
6
7
# File 'lib/tweet_watch/config.rb', line 5

def error_message
  @error_message
end

#pathObject

Returns the value of attribute path.



3
4
5
# File 'lib/tweet_watch/config.rb', line 3

def path
  @path
end

#tweetersObject

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 (screen_name = nil)
   = @accounts.first
  
  unless screen_name.nil?
    res = @accounts.select { |u| u.screen_name.strip() == screen_name.strip() }
     = res.first if res.size > 0
  end
  
  return 
  
end

#has_tweeter?(tweeter) ⇒ Boolean

Returns:

  • (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

Returns:

  • (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