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
# File 'lib/talks/configuration.rb', line 31

def initialize(opts)
  @options = symbolize_hash_keys(opts)

  set_default_options
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



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

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

#message(type) ⇒ Object



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

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

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



53
54
55
56
57
58
59
# File 'lib/talks/configuration.rb', line 53

def message_for(command_name, position = :after, kind = 'message')
  command = command_name.to_sym
  message = \
    position == :before ? "before_#{kind}" : "after_#{kind}"

  options[command][message.to_sym] if options[command]
end

#notifier_for(command_name) ⇒ Object



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

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



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

def notify_message_for(command_name, position = :after)
  message_for(command_name, position, 'notify')
end

#talk(type) ⇒ Object



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

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

#voice(type) ⇒ Object



37
38
39
# File 'lib/talks/configuration.rb', line 37

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