alba_habla 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 347e188fb36dc48d56e0fb6722c448f7c505bf8a
4
- data.tar.gz: df82debec97f3e2cf4ea431c2b419f658af5d124
3
+ metadata.gz: f68da23652a8ceb37915444b4365fa587e46f841
4
+ data.tar.gz: f8c4330c5a41e2788382f81f994bdd6ca6eb2961
5
5
  SHA512:
6
- metadata.gz: 12dcdcde86afef2a4bba5abcbf3f9eb8502a3a6ec3f8bb584b544e7e8dc4a8ee7970136e3eb3f798e3488a20a025105e8d7c4a9dd1f7c307a99f9663e0eeae42
7
- data.tar.gz: 525b8029f3d8c88f47b83476a310f189209241ade9d750fee52165192c26fd5829c0aeee3c35adb053c72e9fb74a0989c2f3bee2369cac3a7633a1dc12e81fb0
6
+ metadata.gz: d37412a5f88bb9b6f13ff9b1ebcee29c5261638fa21e9667855d24e7a94e60d2319befcff6669299db438576aa2692fb9ddee5957fe16900628aa549b1ea8740
7
+ data.tar.gz: 1c22ac349ed0a1e17695dfdfee662738aaaf08981d773126def3f33ded6d1e1da53737ba68d42a11226a59c60c3d0cd332e17688762ee6e01e616a3095664324
data/README.md CHANGED
@@ -1,19 +1,19 @@
1
1
  # Alba Habla
2
2
 
3
- _A fun little wrapper around you OS's speech synthesizer_
3
+ _A fun little wrapper around your OS's speech synthesizer_
4
4
 
5
5
  ## Installation
6
6
 
7
- ```ruby
8
- $ git clone git@github.com:mertonium/alba_habla.git
9
- $ cd alba_habla
10
- $ gem build alba_habla.gemspec
11
- $ gem install ./alba_habla-0.0.1.gem
7
+ Your system will need either `say` or [`espeak`](https://en.wikipedia.org/wiki/ESpeakNG) installed (if you're on a Mac, `say` should already be installed).
8
+ ```
9
+ $ gem install alba_habla
12
10
  ```
13
11
 
14
12
  ## Execution
15
13
 
16
- ```bash
14
+ ```
17
15
  $ alba_habla
16
+ What shall I say?
18
17
  ```
19
18
 
19
+ **Note:** to exit the program, just say "bye".
data/bin/alba_habla CHANGED
@@ -2,7 +2,8 @@
2
2
  require 'io/console'
3
3
  require 'alba_habla'
4
4
 
5
- ah = AlbaHabla.new(File.expand_path(File.dirname(__FILE__)) + '/books/')
5
+ cli_options = AlbaHabla::Cli.parse(ARGV)
6
+ ah = AlbaHabla::Commands.new(cli_options[:book_path])
6
7
 
7
8
  command = nil
8
9
  command_history = []
data/lib/alba_habla.rb CHANGED
@@ -1,89 +1,6 @@
1
- # Main class used to process commands
2
- class AlbaHabla
3
- attr_reader :voice
1
+ require 'alba_habla/commands'
2
+ require 'alba_habla/cli'
4
3
 
5
- VERSION = '0.0.1'.freeze
6
-
7
- DEFAULT_VOICES = {
8
- 'say' => 'Fiona',
9
- 'espeak' => 'en-westindies'
10
- }.freeze
11
-
12
- def initialize(book_path)
13
- @voice = DEFAULT_VOICES[executable]
14
- @book_path = book_path
15
- end
16
-
17
- def process_command(command)
18
- subcommand = command.split(' ').first
19
- if available_subcommands.include? subcommand
20
- send(subcommand, command.split(' ')[1..-1].join(' '))
21
- else
22
- talk(command)
23
- end
24
- end
25
-
26
- private
27
-
28
- def executable
29
- @executable ||= %w[espeak say].reject do |ex|
30
- `which #{ex}` == ''
31
- end.first
32
- end
33
-
34
- def cli_options
35
- "-v #{voice}"
36
- end
37
-
38
- def talk_command
39
- "#{executable} #{cli_options}"
40
- end
41
-
42
- def talk(string)
43
- `#{talk_command} "#{string}"`
44
- end
45
-
46
- def books
47
- {
48
- 'sam' => 'green_eggs_and_ham.txt',
49
- 'cat' => 'the_cat_in_the_hat.txt',
50
- 'ladybird' => 'what_the_ladybird_heard.txt',
51
- 'ladybird2' => 'what_the_lady_bird_heard_next.txt',
52
- 'fox' => 'fox_in_socks.txt'
53
- }
54
- end
55
-
56
- def word_bag
57
- @word_bag || begin
58
- bag = []
59
- books.values.each do |book_file|
60
- IO.foreach(@book_path + book_file) do |line|
61
- bag << line.gsub(/[,'\.!\?]/, '').split(' ')
62
- end
63
- end
64
- bag.flatten.compact.uniq
65
- end
66
- end
67
-
68
- def read(book_name)
69
- if books.key? book_name
70
- IO.foreach(@book_path + books[book_name]) do |line|
71
- puts line
72
- talk line.delete('"')
73
- end
74
- else
75
- talk "Sorry, I don't know that book. Ask Daddy to add it."
76
- end
77
- end
78
-
79
- def spell(_)
80
- word = word_bag.sample
81
- puts word.downcase
82
- talk "Let's spell #{word}."
83
- talk word.split('').join(' ').to_s
84
- end
85
-
86
- def available_subcommands
87
- %w[read spell]
88
- end
4
+ module AlbaHabla
5
+ VERSION = '0.0.2'.freeze
89
6
  end
@@ -0,0 +1,25 @@
1
+ require 'optparse'
2
+
3
+ module AlbaHabla
4
+ # Class used to parse command line arguments
5
+ class Cli
6
+ DEFAULT_OPTIONS = {
7
+ book_path: '',
8
+ }.freeze
9
+
10
+ def self.parse(args)
11
+ options = DEFAULT_OPTIONS.dup
12
+
13
+ opt_parser = OptionParser.new do |opts|
14
+ opts.banner = 'Usage: alba_habla [options]'
15
+
16
+ opts.on('-bBOOK_PATH', '--books=BOOK_PATH', 'Path to folder with book files') do |bp|
17
+ options[:book_path] = bp.end_with?('/') ? bp : "#{bp}/"
18
+ end
19
+ end
20
+
21
+ opt_parser.parse!(args)
22
+ options
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,89 @@
1
+ module AlbaHabla
2
+ # Main class used to process commands
3
+ class Commands
4
+ attr_reader :voice
5
+
6
+ DEFAULT_VOICES = {
7
+ 'say' => 'Fiona',
8
+ 'espeak' => 'en-westindies',
9
+ }.freeze
10
+
11
+ def initialize(book_path)
12
+ @voice = DEFAULT_VOICES[executable]
13
+ @book_path = book_path
14
+ end
15
+
16
+ def process_command(command)
17
+ subcommand = command.split(' ').first
18
+ if available_subcommands.include? subcommand
19
+ send(subcommand, command.split(' ')[1..-1].join(' '))
20
+ else
21
+ talk(command)
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def executable
28
+ @executable ||= %w[espeak say].reject do |ex|
29
+ `which #{ex}` == ''
30
+ end.first
31
+ end
32
+
33
+ def cli_options
34
+ "-v #{voice}"
35
+ end
36
+
37
+ def talk_command
38
+ "#{executable} #{cli_options}"
39
+ end
40
+
41
+ def talk(string)
42
+ `#{talk_command} "#{string}"`
43
+ end
44
+
45
+ def books
46
+ {
47
+ 'sam' => 'green_eggs_and_ham.txt',
48
+ 'cat' => 'the_cat_in_the_hat.txt',
49
+ 'ladybird' => 'what_the_ladybird_heard.txt',
50
+ 'ladybird2' => 'what_the_lady_bird_heard_next.txt',
51
+ 'fox' => 'fox_in_socks.txt',
52
+ }
53
+ end
54
+
55
+ def word_bag
56
+ @word_bag || begin
57
+ bag = []
58
+ books.values.each do |book_file|
59
+ IO.foreach(@book_path + book_file) do |line|
60
+ bag << line.gsub(/[,'\.!\?]/, '').split(' ')
61
+ end
62
+ end
63
+ bag.flatten.compact.uniq
64
+ end
65
+ end
66
+
67
+ def read(book_name)
68
+ if books.key? book_name
69
+ IO.foreach(@book_path + books[book_name]) do |line|
70
+ puts line
71
+ talk line.delete('"')
72
+ end
73
+ else
74
+ talk "Sorry, I don't know that book. Ask Daddy to add it."
75
+ end
76
+ end
77
+
78
+ def spell(_)
79
+ word = word_bag.sample
80
+ puts word.downcase
81
+ talk "Let's spell #{word}."
82
+ talk word.split('').join(' ').to_s
83
+ end
84
+
85
+ def available_subcommands
86
+ %w[read spell]
87
+ end
88
+ end
89
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alba_habla
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mertonium
@@ -48,6 +48,8 @@ files:
48
48
  - README.md
49
49
  - bin/alba_habla
50
50
  - lib/alba_habla.rb
51
+ - lib/alba_habla/cli.rb
52
+ - lib/alba_habla/commands.rb
51
53
  homepage: https://github.com/mertonium/alba_habla
52
54
  licenses:
53
55
  - MIT