Class: Akane::Config
- Inherits:
-
Object
- Object
- Akane::Config
- Defined in:
- lib/akane/config.rb
Instance Method Summary collapse
- #[](k) ⇒ Object
- #consumer ⇒ Object
-
#initialize(file_or_hash) ⇒ Config
constructor
A new instance of Config.
- #log_direct(line) ⇒ Object
- #logger ⇒ Object
Constructor Details
#initialize(file_or_hash) ⇒ Config
Returns a new instance of Config.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/akane/config.rb', line 7 def initialize(file_or_hash) @hash = case file_or_hash when String YAML.load_file(file_or_hash) when Hash file_or_hash else raise ArgumentError, 'file_or_hash is not Hash or String' end end |
Instance Method Details
#[](k) ⇒ Object
18 19 20 |
# File 'lib/akane/config.rb', line 18 def [](k) @hash[k.to_s] end |
#consumer ⇒ Object
22 23 24 25 26 27 |
# File 'lib/akane/config.rb', line 22 def consumer consumer = self[:consumer] return nil unless consumer OAuth::Consumer.new(consumer['token'], consumer['secret'], site: 'https://api.twitter.com/') end |
#log_direct(line) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/akane/config.rb', line 33 def log_direct(line) if @hash["log"] open(@hash["log"], 'a') do |io| io.puts line end else $stdout.puts line end end |
#logger ⇒ Object
29 30 31 |
# File 'lib/akane/config.rb', line 29 def logger Logger.new(@hash["log"] || $stdout) end |