Class: Talks::Configuration
- Inherits:
-
Object
- Object
- Talks::Configuration
- 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
-
#default_voice ⇒ Object
Returns the value of attribute default_voice.
-
#detach ⇒ Object
Returns the value of attribute detach.
-
#engine ⇒ Object
Returns the value of attribute engine.
-
#messages ⇒ Object
Returns the value of attribute messages.
-
#notifier ⇒ Object
Returns the value of attribute notifier.
-
#notifier_options ⇒ Object
Returns the value of attribute notifier_options.
-
#notify_by_default ⇒ Object
Returns the value of attribute notify_by_default.
-
#options ⇒ Object
Returns the value of attribute options.
-
#voices ⇒ Object
Returns the value of attribute voices.
Instance Method Summary collapse
- #default_message_for(command_name, position = :after) ⇒ Object
-
#initialize(opts) ⇒ Configuration
constructor
A new instance of Configuration.
- #message(type) ⇒ Object
- #message_for(command_name, position = :after) ⇒ Object
- #notifier_for(command_name) ⇒ Object
- #notify_message_for(command_name, position = :after) ⇒ Object
- #talk(type) ⇒ Object
- #voice(type) ⇒ Object
- #voice_for(command_name) ⇒ Object
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 = [:engine] || default_engine_for_os @notifier_options = [:notifier_options] || {} @detach = [:detach] @notify_by_default = [:notify_by_default] @default_voice = [:default_voice] || default_voice_for(engine) @voices = [:voices] && DEFAULT_VOICES[engine.to_sym].merge([:voices]) || DEFAULT_VOICES[engine.to_sym] @messages = [:messages] && DEFAULT_MESSAGES.merge([:messages]) || DEFAULT_MESSAGES end |
Instance Attribute Details
#default_voice ⇒ Object
Returns the value of attribute default_voice.
28 29 30 |
# File 'lib/talks/configuration.rb', line 28 def default_voice @default_voice end |
#detach ⇒ Object
Returns the value of attribute detach.
28 29 30 |
# File 'lib/talks/configuration.rb', line 28 def detach @detach end |
#engine ⇒ Object
Returns the value of attribute engine.
28 29 30 |
# File 'lib/talks/configuration.rb', line 28 def engine @engine end |
#messages ⇒ Object
Returns the value of attribute messages.
28 29 30 |
# File 'lib/talks/configuration.rb', line 28 def @messages end |
#notifier ⇒ Object
Returns the value of attribute notifier.
28 29 30 |
# File 'lib/talks/configuration.rb', line 28 def notifier @notifier end |
#notifier_options ⇒ Object
Returns the value of attribute notifier_options.
28 29 30 |
# File 'lib/talks/configuration.rb', line 28 def @notifier_options end |
#notify_by_default ⇒ Object
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 |
#options ⇒ Object
Returns the value of attribute options.
28 29 30 |
# File 'lib/talks/configuration.rb', line 28 def @options end |
#voices ⇒ Object
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 (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 (type) [type] if .keys.include?(type) end |
#message_for(command_name, position = :after) ⇒ Object
60 61 62 63 64 |
# File 'lib/talks/configuration.rb', line 60 def (command_name, position = :after) command = command_name.to_sym [command] && [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 ([:notifier] != 'off') && ( ![command] || ([command] && ([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 (command_name, position = :after) command = command_name.to_sym [command] && [command][(position == :before ? :before_notify : :after_notify)] end |
#talk(type) ⇒ Object
52 53 54 |
# File 'lib/talks/configuration.rb', line 52 def talk(type) [(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 [command] && [command][:voice] end |