james 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,7 @@
1
1
  module James; end
2
2
 
3
+ require File.expand_path '../james/preferences', __FILE__
4
+
3
5
  require File.expand_path '../james/state_api', __FILE__
4
6
  require File.expand_path '../james/state_internals', __FILE__
5
7
 
@@ -44,7 +44,7 @@ class CoreDialog
44
44
  #
45
45
  state :exit do
46
46
  into do
47
- puts "James: Exits through a side door."
47
+ puts "James exits through a side door."
48
48
  Kernel.exit
49
49
  end
50
50
  end
@@ -28,6 +28,7 @@ module James
28
28
  def initialize dialog = nil
29
29
  @initial = dialog || CoreDialog.new
30
30
  @conversation = Conversation.new @initial.current
31
+ @preferences = James::Preferences.new
31
32
  end
32
33
 
33
34
  # Convenience method to add a dialog to the current system.
@@ -53,9 +54,6 @@ module James
53
54
  @input_class = options[:input] || Inputs::Audio
54
55
  @output_class = options[:output] || Outputs::Audio
55
56
 
56
- @output_options ||= {}
57
- @output_options[:voice] = options[:voice] || 'com.apple.speech.synthesis.voice.Alex'
58
-
59
57
  app = NSApplication.sharedApplication
60
58
  app.delegate = self
61
59
 
@@ -84,7 +82,7 @@ module James
84
82
  # Start speaking.
85
83
  #
86
84
  def start_output
87
- @output = @output_class.new @output_options
85
+ @output = @output_class.new @preferences
88
86
  end
89
87
 
90
88
  # Callback method from dialog.
@@ -7,10 +7,10 @@ module James
7
7
  # Create a new audio output.
8
8
  #
9
9
  # Options:
10
- # * voice # Default is 'com.apple.speech.synthesis.voice.Alex'.
10
+ # * preferences # A James::Preferences
11
11
  #
12
- def initialize options = {}
13
- @output = NSSpeechSynthesizer.alloc.initWithVoice options[:voice] || 'com.apple.speech.synthesis.voice.Alex'
12
+ def initialize preferences
13
+ @output = NSSpeechSynthesizer.alloc.initWithVoice preferences.voice
14
14
  end
15
15
 
16
16
  # Say the given text out loud.
@@ -8,7 +8,7 @@ module James
8
8
 
9
9
  #
10
10
  #
11
- def initialize options = {}
11
+ def initialize preferences = nil
12
12
 
13
13
  end
14
14
 
@@ -0,0 +1,60 @@
1
+ require 'yaml'
2
+
3
+ module James
4
+
5
+ # This class loads the .james preferences
6
+ # and handles them.
7
+ #
8
+ # The preferences are loaded once, at startup. To reload
9
+ # the preferences, you have to restart James.
10
+ #
11
+ # It loads them in the following order of precedence:
12
+ # * .james
13
+ # * ~/.james
14
+ #
15
+ # If no dotfile is found, it will
16
+ #
17
+ class Preferences
18
+
19
+ attr_reader :preferences
20
+
21
+ def initialize
22
+ load
23
+ end
24
+
25
+ # Preference accessors & defaults.
26
+ #
27
+
28
+ # Default is the OSX Alex voice.
29
+ #
30
+ def voice
31
+ preferences['voice'] || 'com.apple.speech.synthesis.voice.Alex'
32
+ end
33
+
34
+ # Loads a set of preferences.
35
+ #
36
+ def load
37
+ @preferences = load_from_file || {}
38
+ end
39
+
40
+ # Load the preferences from a file if
41
+ # a suitable .james is found.
42
+ #
43
+ def load_from_file
44
+ dotfile = find_file
45
+ YAML.load_file dotfile if dotfile
46
+ end
47
+
48
+ # Finds dotfiles in order of precedence.
49
+ # * .james
50
+ # * ~/.james
51
+ #
52
+ # Returns nil if none is found.
53
+ #
54
+ def find_file
55
+ Dir['.james', File.expand_path('~/.james')].first
56
+ end
57
+
58
+ end
59
+
60
+ end
metadata CHANGED
@@ -1,38 +1,41 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: james
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.5.0
5
+ version: 0.6.0
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Florian Hanke
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-06-15 00:00:00 +10:00
12
+ date: 2011-06-28 00:00:00 +10:00
14
13
  default_executable: james
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
17
16
  name: rspec
18
17
  prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
18
+ requirement: !ruby/object:Gem::Requirement
20
19
  none: false
21
- requirements:
22
- - - ">="
23
- - !ruby/object:Gem::Version
20
+ requirements:
21
+ - - '>='
22
+ - !ruby/object:Gem::Version
24
23
  version: "0"
25
24
  type: :development
26
- version_requirements: *id001
27
- description: Modular Electronic Butler. Using a simple dialog system where you can easily add more dialogs.
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - '>='
29
+ - !ruby/object:Gem::Version
30
+ version: "0"
31
+ description: Modular Electronic Butler. Using a simple dialog system where you can
32
+ easily add more dialogs.
28
33
  email: florian.hanke+james@gmail.com
29
- executables:
34
+ executables:
30
35
  - james
31
36
  extensions: []
32
-
33
37
  extra_rdoc_files: []
34
-
35
- files:
38
+ files:
36
39
  - lib/james/builtin/core_dialog.rb
37
40
  - lib/james/controller.rb
38
41
  - lib/james/conversation.rb
@@ -48,6 +51,7 @@ files:
48
51
  - lib/james/markers/memory.rb
49
52
  - lib/james/outputs/audio.rb
50
53
  - lib/james/outputs/terminal.rb
54
+ - lib/james/preferences.rb
51
55
  - lib/james/state_api.rb
52
56
  - lib/james/state_internals.rb
53
57
  - lib/james.rb
@@ -56,30 +60,26 @@ files:
56
60
  has_rdoc: true
57
61
  homepage: http://floere.github.com/james
58
62
  licenses: []
59
-
60
63
  post_install_message:
61
64
  rdoc_options: []
62
-
63
- require_paths:
65
+ require_paths:
64
66
  - lib
65
- required_ruby_version: !ruby/object:Gem::Requirement
67
+ required_ruby_version: !ruby/object:Gem::Requirement
66
68
  none: false
67
- requirements:
68
- - - ">="
69
- - !ruby/object:Gem::Version
69
+ requirements:
70
+ - - '>='
71
+ - !ruby/object:Gem::Version
70
72
  version: "0"
71
- required_rubygems_version: !ruby/object:Gem::Requirement
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
74
  none: false
73
- requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
75
+ requirements:
76
+ - - '>='
77
+ - !ruby/object:Gem::Version
76
78
  version: "0"
77
79
  requirements: []
78
-
79
80
  rubyforge_project:
80
- rubygems_version: 1.5.0
81
+ rubygems_version: 1.4.2
81
82
  signing_key:
82
83
  specification_version: 3
83
- summary: "James: Modular Electronic Butler with modular Dialogs."
84
+ summary: 'James: Modular Electronic Butler with modular Dialogs.'
84
85
  test_files: []
85
-