talks 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,11 +1,13 @@
1
- # Talks gem — now your ruby on your mac can talk with you
1
+ # Talks gem — now your ruby can talk with you
2
2
 
3
- ### This is beta now
3
+ ### Now it works only on MacOS X, soon we'll add support for linux and maybe windows through eSpeak or festival
4
4
 
5
- ## It was checked only on MacOS X. I don't know what present on linux or windows
5
+ ### This is beta now
6
6
 
7
7
  If you want to HEAR some response from your code, just use this gem.
8
8
 
9
+ Sponsored by Evil Martians <http://evilmartians.com>
10
+
9
11
  ## Why?
10
12
 
11
13
  For example - some really long task and you just get some coffee, read book or surf internet
@@ -17,6 +19,23 @@ choose from MacOS X `say` function collection.
17
19
 
18
20
  This gem just using native MacOS X `say` command line tool.
19
21
 
22
+ ### Configuration
23
+
24
+ You can configure default voices and messages for `talks` with `~/.talksrc` file. It should be written in YAML format:
25
+
26
+ `~/.talksrc`
27
+ ```yml
28
+ default_voice: 'whisper'
29
+ voices:
30
+ info: 'pipe'
31
+ messages:
32
+ info: 'hello'
33
+ warn: 'WE GONNA DIE!!!'
34
+ ```
35
+
36
+ The same you can do in your code dynamicly through Talks.config instance.
37
+ Soon I'll add configuration with dotfile project-wide.
38
+
20
39
  ### Using talks in your code
21
40
 
22
41
  ```bash
@@ -1,3 +1,5 @@
1
+ require File.expand_path('../talks/configuration.rb', __FILE__)
2
+
1
3
  module Talks
2
4
  class << self
3
5
 
@@ -7,19 +9,12 @@ module Talks
7
9
  trinoids vicki victoria whisper zarvox
8
10
  )
9
11
 
10
- PREFS = {
11
- info: 'vicki',
12
- warn: 'whisper',
13
- success: 'vicki',
14
- error: 'bad'
15
- }
12
+ TYPES = [:info, :warn, :success, :error]
16
13
 
17
- def voice
18
- @voice ||= :info
19
- end
14
+ attr :config
20
15
 
21
- def voice=(voice = :info)
22
- @voice ||= voice
16
+ def configure(options)
17
+ @config = Talks::Configuration.new(options)
23
18
  end
24
19
 
25
20
  def voices
@@ -27,23 +22,30 @@ module Talks
27
22
  end
28
23
 
29
24
  def say(message, options = {})
30
- type = options[:type].to_sym if options[:type]
31
- say_voice = \
32
- if options[:voice] and VOICES.include?(options[:voice].to_s)
33
- options[:voice]
34
- elsif PREFS.keys.include? type
35
- PREFS[type]
36
- else
37
- PREFS[voice]
38
- end
39
- `say -v #{say_voice} #{message}`
25
+ type = options[:type] || :default
26
+ `say -v #{say_voice(type, options)} #{message}`
40
27
  end
41
28
 
42
- PREFS.keys.each do |type|
43
- define_method type do |message, options = {type: type}|
29
+ TYPES.each do |type|
30
+ define_method type do |message = nil, options = {type: type}|
31
+ message ||= config.message(type)
44
32
  say(message, options)
45
33
  end
46
34
  end
47
35
 
36
+ private
37
+
38
+ def say_voice(type, options)
39
+ if options[:voice] and VOICES.include?(options[:voice].to_s)
40
+ options[:voice]
41
+ elsif TYPES.include? type
42
+ config.voice type
43
+ else
44
+ config.default_voice
45
+ end
46
+ end
47
+
48
48
  end
49
49
  end
50
+
51
+ require File.expand_path('../talks/runner.rb', __FILE__)
@@ -0,0 +1,55 @@
1
+ require 'yaml'
2
+
3
+ module Talks
4
+ class Configuration
5
+
6
+ DEFAULT_VOICES = {
7
+ info: 'vicki',
8
+ warn: 'whisper',
9
+ success: 'vicki',
10
+ error: 'bad'
11
+ }
12
+
13
+ DEFAULT_MESSAGES = {
14
+ info: 'Information note',
15
+ warn: 'Warning',
16
+ success: 'Success',
17
+ error: 'Error'
18
+ }
19
+
20
+ attr_accessor :voices, :messages, :default_voice, :options
21
+
22
+ def initialize(opts)
23
+ @options = symbolize_hash_keys(opts)
24
+ @default_voice = options[:default_voice] || 'vicki'
25
+ @voices = options[:voices] && DEFAULT_VOICES.merge(options[:voices]) ||
26
+ DEFAULT_VOICES
27
+ @messages = options[:messages] && DEFAULT_MESSAGES.merge(options[:messages]) ||
28
+ DEFAULT_MESSAGES
29
+ end
30
+
31
+ def voice(type)
32
+ voices[type] if voices.keys.include?(type)
33
+ end
34
+
35
+ def message(type)
36
+ messages[type] if messages.keys.include?(type)
37
+ end
38
+
39
+ def talk(type)
40
+ [message(type), voice(type)]
41
+ end
42
+
43
+ private
44
+
45
+ def symbolize_hash_keys(opts)
46
+ sym_opts = {}
47
+ opts.each do |key, value|
48
+ sym_opts[key.to_sym] = \
49
+ value.is_a?(Hash) ? symbolize_hash_keys(value) : value
50
+ end
51
+ sym_opts
52
+ end
53
+
54
+ end
55
+ end
@@ -0,0 +1,20 @@
1
+ # What file is used for talks startup configuration.
2
+ unless defined?(OPTS_INITFILE)
3
+ if RUBY_PLATFORM =~ /mswin/
4
+ # Of course MS Windows has to be different
5
+ OPTS_INITFILE = 'talks.ini'
6
+ HOME_DIR = (ENV['HOME'] ||
7
+ ENV['HOMEDRIVE'].to_s + ENV['HOMEPATH'].to_s).to_s
8
+ else
9
+ OPTS_INITFILE = '.talksrc'
10
+ HOME_DIR = ENV['HOME'].to_s
11
+ end
12
+ end
13
+
14
+ initfile = File.join(HOME_DIR, OPTS_INITFILE)
15
+
16
+ if File.exist?(initfile)
17
+ Talks.configure(YAML.load_file(initfile))
18
+ else
19
+ Talks.configure({})
20
+ end
@@ -1,3 +1,3 @@
1
1
  module Talks
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
@@ -2,11 +2,24 @@ require File.expand_path('../../lib/talks.rb', __FILE__)
2
2
 
3
3
  Talks.voices.each do |v|
4
4
  p v
5
- Talks.say 'Tests start', nil, voice: v
5
+ Talks.say 'Tests start', voice: v
6
6
  end
7
7
 
8
+ p 'say `say`'
8
9
  Talks.say 'say'
10
+ p 'info `say again`'
9
11
  Talks.info 'say again'
12
+ p 'warn `I warn you`'
10
13
  Talks.warn 'I warn you'
14
+ p 'error `This is how error sounds`'
11
15
  Talks.error 'This is how error sounds'
16
+ p 'success `This is success!`'
12
17
  Talks.success 'This is success!'
18
+ p 'info `default`'
19
+ Talks.info
20
+ p 'warn `default`'
21
+ Talks.warn
22
+ p 'warn `error`'
23
+ Talks.error
24
+ p 'warn `success`'
25
+ Talks.success
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: talks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-22 00:00:00.000000000 Z
12
+ date: 2012-05-23 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Simple gem for `say` function of mac os x
15
15
  email:
@@ -20,10 +20,11 @@ extra_rdoc_files: []
20
20
  files:
21
21
  - CHANGELOG.md
22
22
  - Gemfile
23
- - Gemfile.lock
24
23
  - README.md
25
24
  - Rakefile
26
25
  - lib/talks.rb
26
+ - lib/talks/configuration.rb
27
+ - lib/talks/runner.rb
27
28
  - lib/talks/version.rb
28
29
  - spec/talks.rb
29
30
  - talks.gemspec
@@ -1,14 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- talks (0.0.2)
5
-
6
- GEM
7
- remote: http://rubygems.org/
8
- specs:
9
-
10
- PLATFORMS
11
- ruby
12
-
13
- DEPENDENCIES
14
- talks!