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.



30
31
32
33
34
35
36
37
38
# File 'lib/talks/configuration.rb', line 30

def initialize(opts)
  @options = symbolize_hash_keys(opts)
  @engine = options[:engine] || default_engine_for_os
  @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

#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

#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



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

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

#message(type) ⇒ Object



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

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

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



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

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



62
63
64
65
66
67
# File 'lib/talks/configuration.rb', line 62

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

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



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

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



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

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

#voice(type) ⇒ Object



40
41
42
# File 'lib/talks/configuration.rb', line 40

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

#voice_for(command_name) ⇒ Object



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

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