Class: Talks::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/talks/configuration.rb

Constant Summary collapse

DEFAULT_VOICES =
{
  :say => {
    :info    => 'vicki',
    :warn    => 'whisper',
    :success => 'vicki',
    :error   => 'bad'
  },
  :espeak => {
    :info    => 'en+f3',
    :warn    => 'en+m1',
    :success => 'en+f3',
    :error   => 'en+m3'
  }
}
DEFAULT_MESSAGES =
{
  :info    => 'Information note',
  :warn    => 'Warning',
  :success => 'Success',
  :error   => 'Error'
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Configuration

Returns a new instance of Configuration.



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/talks/configuration.rb', line 31

def initialize(opts)
  @options = symbolize_hash_keys(opts)
  @engine = options[:engine] || default_engine_for_os
  @notifier_options = options[:notifier_options] || {}
  @detach = options[:detach]
  @notify_by_default = options[:notify_by_default]
  @default_voice = options[:default_voice] || default_voice_for(engine)
  @voices = options[:voices] && DEFAULT_VOICES[engine.to_sym].merge(options[:voices]) ||
    DEFAULT_VOICES[engine.to_sym]
  @messages = options[:messages] && DEFAULT_MESSAGES.merge(options[:messages]) ||
    DEFAULT_MESSAGES
end

Instance Attribute Details

#default_voiceObject

Returns the value of attribute default_voice.



28
29
30
# File 'lib/talks/configuration.rb', line 28

def default_voice
  @default_voice
end

#detachObject

Returns the value of attribute detach.



28
29
30
# File 'lib/talks/configuration.rb', line 28

def detach
  @detach
end

#engineObject

Returns the value of attribute engine.



28
29
30
# File 'lib/talks/configuration.rb', line 28

def engine
  @engine
end

#messagesObject

Returns the value of attribute messages.



28
29
30
# File 'lib/talks/configuration.rb', line 28

def messages
  @messages
end

#notifierObject

Returns the value of attribute notifier.



28
29
30
# File 'lib/talks/configuration.rb', line 28

def notifier
  @notifier
end

#notifier_optionsObject

Returns the value of attribute notifier_options.



28
29
30
# File 'lib/talks/configuration.rb', line 28

def notifier_options
  @notifier_options
end

#notify_by_defaultObject

Returns the value of attribute notify_by_default.



28
29
30
# File 'lib/talks/configuration.rb', line 28

def notify_by_default
  @notify_by_default
end

#optionsObject

Returns the value of attribute options.



28
29
30
# File 'lib/talks/configuration.rb', line 28

def options
  @options
end

#voicesObject

Returns the value of attribute voices.



28
29
30
# File 'lib/talks/configuration.rb', line 28

def voices
  @voices
end

Instance Method Details

#default_message_for(command_name, position = :after) ⇒ Object



56
57
58
# File 'lib/talks/configuration.rb', line 56

def default_message_for(command_name, position = :after)
  "#{command_name} task #{position == :before ? 'started' : 'ended'}"
end

#message(type) ⇒ Object



48
49
50
# File 'lib/talks/configuration.rb', line 48

def message(type)
  messages[type] if messages.keys.include?(type)
end

#message_for(command_name, position = :after) ⇒ Object



60
61
62
63
64
# File 'lib/talks/configuration.rb', line 60

def message_for(command_name, position = :after)
  command = command_name.to_sym
  options[command] &&
    options[command][(position == :before ? :before_message : :after_message)]
end

#notifier_for(command_name) ⇒ Object



66
67
68
69
70
71
72
73
74
# File 'lib/talks/configuration.rb', line 66

def notifier_for(command_name)
  command = command_name.to_sym
  (options[:notifier] != 'off') &&
    (
      !options[command] ||
      (options[command] &&
      (options[command][:notifier] != 'off'))
    )
end

#notify_message_for(command_name, position = :after) ⇒ Object



76
77
78
79
80
# File 'lib/talks/configuration.rb', line 76

def notify_message_for(command_name, position = :after)
  command = command_name.to_sym
  options[command] &&
    options[command][(position == :before ? :before_notify : :after_notify)]
end

#talk(type) ⇒ Object



52
53
54
# File 'lib/talks/configuration.rb', line 52

def talk(type)
  [message(type), voice(type)]
end

#voice(type) ⇒ Object



44
45
46
# File 'lib/talks/configuration.rb', line 44

def voice(type)
  voices[type] if voices.keys.include?(type)
end

#voice_for(command_name) ⇒ Object



82
83
84
85
86
# File 'lib/talks/configuration.rb', line 82

def voice_for(command_name)
  command = command_name.to_sym
  options[command] &&
    options[command][:voice]
end