termit 2.0.5 → 2.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4537bfa028218580e77d2d3776c94678c90be432
4
- data.tar.gz: 085aed266a94a21e8a2a728354af7178e7a22e84
3
+ metadata.gz: e30065a5242cf4e4aa3768265c44ecac3b8b2f2d
4
+ data.tar.gz: 546fcbe56d7a5f9ad22490545013650f440c9a31
5
5
  SHA512:
6
- metadata.gz: 3366fa5030a8aa6a33f7844bbf18e199b38cc23ce479ae72d6491362496b082a7ff52f2cbb09b3eb915d0fa890d51de66f9d1358f8091c641d61c7791c7d80a5
7
- data.tar.gz: 177665e7477889fc95d7fed634945e864646f4d5d689a26b4f703649d7f2407e14624a8556f84830dc9c7692ccda73e412472628c2f61b14579888177cf6dd09
6
+ metadata.gz: 54db1363b236b0d1720b875e4406a49b51ce6492c4155e6db6fdca7f26eb241f9afdd8c19d8cafdfd3768a90d3806b91671d580fdf3639ba28f5e047faa519eb
7
+ data.tar.gz: 3d4bf47dcea58ee04569bcd82061883fc7dfdeb3ff22208f566ca099322a327ee6a275d1238999be313d2138aa167c5c9dbfe3a2daa392d053555b709adbafd5
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  #Termit [![Build Status](https://travis-ci.org/pawurb/termit.png)](https://travis-ci.org/pawurb/termit) [![Gem Version](https://badge.fury.io/rb/termit.png)](http://badge.fury.io/rb/termit)
2
2
 
3
3
 
4
- Termit is an easy way to use Google Translate in your terminal. It does not use paid Google Translate API but instead it headlessly browses www.translate.google.com and parses the response.
4
+ Termit is an easy way to use Google Translate in your terminal.
5
5
 
6
6
  ## Installation
7
7
  ```ruby
@@ -31,9 +31,9 @@ termit fr ru qui est votre papa?
31
31
  ```
32
32
  #### Speech synthesis
33
33
 
34
- Specify a **-t** (talk) flag to use speech synthesis:
34
+ Specify a **-t** (talk) flag to use speech synthesis (requires mpg123):
35
35
  ``` ruby
36
- termit en zh "hey cowboy where is your horse?" -v
36
+ termit en zh "hey cowboy where is your horse?" -t
37
37
  => "嘿,牛仔是你的马在哪里?" #and a chinese voice says something about a horse
38
38
  ```
39
39
 
@@ -64,7 +64,7 @@ To find all available language codes visit www.translate.google.com. Choose lang
64
64
 
65
65
  Works with Ruby 1.9.2 and higher.
66
66
 
67
- To use speech synthesis (yes it talks) you need to have mpg123 installed.
67
+ To use speech synthesis you need to have mpg123 installed.
68
68
 
69
69
  For Ubuntu:
70
70
 
@@ -74,11 +74,13 @@ For MacOSX:
74
74
 
75
75
  brew install mpg123
76
76
 
77
+ ## Status
77
78
 
79
+ This is my first open-source project for people to use. Any feedback will be appreciated.
78
80
 
81
+ You can contact me on: p.urbanek89@gmail.com
79
82
 
80
- Any feedback will be appreciated. You can contact me on: p.urbanek89@gmail.com
81
-
83
+ Btw. I am looking for a job as a rails developer now and I am willing to relocate.
82
84
 
83
85
 
84
86
 
@@ -1,12 +1,12 @@
1
1
  #encoding: UTF-8
2
2
  module Termit
3
3
  class OutputManager
4
- def display_error_info
5
- puts "TERMIT: Wrong data. Example: 'termit en es the cowboy ' => 'el vaquero"
4
+ def display_error_info_and_quit
5
+ abort "TERMIT: Wrong data. Example: 'termit en es the cowboy ' => 'el vaquero'"
6
6
  end
7
7
 
8
- def display_help
9
- puts <<-EOS
8
+ def display_help_and_quit
9
+ abort <<-EOS
10
10
  =========TERMIT=========
11
11
  Usage:
12
12
  termit 'source_language' 'target_language' 'text'
@@ -23,8 +23,19 @@ Check docs at: github.com/pawurb/termit
23
23
  EOS
24
24
  end
25
25
 
26
- def display_version
27
- puts "Termit #{Termit::VERSION}"
26
+ def display_player_error_and_quit
27
+ message = "Termit speech synthesis requires mpg123 installed."
28
+ case Gem::Platform.local.os
29
+ when "darwin"
30
+ message << "\nPlease run 'brew install mpg123'"
31
+ when "linux"
32
+ message << "\nPlease run 'sudo apt-get install mpg123'"
33
+ end
34
+ abort message
35
+ end
36
+
37
+ def display_version_and_quit
38
+ abort "Termit #{Termit::VERSION}"
28
39
  end
29
40
 
30
41
  def display_translation text
@@ -36,5 +47,6 @@ EOS
36
47
  print '=> Synonyms: '
37
48
  puts synonyms
38
49
  end
50
+
39
51
  end
40
52
  end
@@ -1,6 +1,10 @@
1
1
  #encoding: UTF-8
2
2
  module Termit
3
3
  class SpeechSynthesizer
4
+ extend ::Delegation
5
+ @output_manager = Termit::OutputManager.new
6
+ delegate :display_player_error_and_quit, to: @output_manager
7
+
4
8
  def initialize options
5
9
  check_sound_player
6
10
  @text = options[:text]
@@ -16,8 +20,8 @@ module Termit
16
20
 
17
21
  def check_sound_player
18
22
  unless system 'which mpg123 > /dev/null'
19
- raise "Termit speech synthesis requires mpg123 installed"
23
+ display_player_error_and_quit
20
24
  end
21
25
  end
22
- end
26
+ end
23
27
  end
@@ -4,14 +4,14 @@ module Termit
4
4
  extend ::Delegation
5
5
  @output_manager = Termit::OutputManager.new
6
6
 
7
- delegate :display_error_info, :display_help, :display_version, to: @output_manager
7
+ delegate :display_error_info_and_quit, :display_help_and_quit, :display_version_and_quit, to: @output_manager
8
+
8
9
  def initialize user_input
9
10
  @user_input = user_input
10
11
  quit_if_required
11
12
  validate_user_input
12
13
  rescue ArgumentError
13
- display_error_info
14
- exit
14
+ display_error_info_and_quit
15
15
  end
16
16
 
17
17
  def options
@@ -44,14 +44,8 @@ module Termit
44
44
  end
45
45
 
46
46
  def quit_if_required
47
- if @user_input.index("-h") || @user_input.empty?
48
- display_help
49
- exit
50
- end
51
- if @user_input.index("-v")
52
- display_version
53
- exit
54
- end
47
+ display_help_and_quit if @user_input.index("-h") || @user_input.empty?
48
+ display_version_and_quit if @user_input.index("-v")
55
49
  end
56
50
  end
57
51
  end
@@ -1,3 +1,3 @@
1
1
  module Termit
2
- VERSION = "2.0.5"
2
+ VERSION = "2.0.6"
3
3
  end
@@ -6,22 +6,25 @@ describe Termit::OutputManager do
6
6
  describe "instance_methods" do
7
7
  describe "display_error_info_and_quit" do
8
8
  it "does what is says" do
9
- expect(STDOUT).to receive(:puts).with("TERMIT: Wrong data. Example: 'termit en es the cowboy ' => 'el vaquero")
10
- subject.display_error_info
9
+ expect { subject.display_error_info_and_quit }.to raise_error SystemExit
11
10
  end
12
11
  end
13
12
 
14
13
  describe "display_help_and_quit" do
15
14
  it "does what is says" do
16
- expect(STDOUT).to receive(:puts)
17
- subject.display_help
15
+ expect { subject.display_help_and_quit }.to raise_error SystemExit
18
16
  end
19
17
  end
20
18
 
21
19
  describe "display_version_and_quit" do
22
20
  it "does what is says" do
23
- expect(STDOUT).to receive(:puts).with("Termit #{Termit::VERSION}")
24
- subject.display_version
21
+ expect { subject.display_version_and_quit }.to raise_error SystemExit
22
+ end
23
+ end
24
+
25
+ describe "display_player_error_and_quit" do
26
+ it "does what is says" do
27
+ expect { subject.display_player_error_and_quit }.to raise_error SystemExit
25
28
  end
26
29
  end
27
30
  end
@@ -11,10 +11,22 @@ describe Termit::SpeechSynthesizer do
11
11
  Termit::SoundResponseHandler.stub(:new) { handler }
12
12
  end
13
13
 
14
- it "executes correct service objects" do
15
- Termit::SpeechSynthesizer.any_instance.stub(:check_sound_player) { nil }
16
- Termit::SoundResponseHandler.should_receive(:new).with(:binary_sound_file)
17
- Termit::SpeechSynthesizer.new(target_lang: :en, text: 'your mother', voice: true).call
14
+ context "system has mpg123 installed" do
15
+ it "executes correct service objects" do
16
+ Termit::SpeechSynthesizer.any_instance.stub(:check_sound_player) { nil }
17
+ Termit::SoundResponseHandler.should_receive(:new).with(:binary_sound_file)
18
+ Termit::SpeechSynthesizer.new(target_lang: :en, text: 'your mother', voice: true).call
19
+ end
20
+ end
21
+
22
+ context "there is no mpq123 installed" do
23
+ before do
24
+ Object.any_instance.stub(:system) { nil }
25
+ end
26
+ it "executes correct service objects" do
27
+ Termit::OutputManager.any_instance.should_receive(:display_player_error_and_quit)
28
+ Termit::SpeechSynthesizer.new(target_lang: :en, text: 'your mother', voice: true).call
29
+ end
18
30
  end
19
31
  end
20
32
  end
@@ -42,9 +42,6 @@ describe Termit::UserInputParser do
42
42
  it "with incorrect language options format raiser error" do
43
43
  expect{ Termit::UserInputParser.new ['ang', 'po polski', 'hey cowboy!', '-t'] }.to raise_error SystemExit
44
44
  end
45
-
46
45
  end
47
-
48
46
  end
49
-
50
47
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: termit
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.5
4
+ version: 2.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - pawurb
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-24 00:00:00.000000000 Z
11
+ date: 2013-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -56,17 +56,17 @@ dependencies:
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- description: ! ' Termit is an easy way to use all the Google Translate goodies straight
69
+ description: ' Termit is an easy way to use all the Google Translate goodies straight
70
70
  from your terminal. '
71
71
  email:
72
72
  - p.urbanek89@gmail.com
@@ -119,12 +119,12 @@ require_paths:
119
119
  - lib
120
120
  required_ruby_version: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ! '>='
122
+ - - '>='
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  required_rubygems_version: !ruby/object:Gem::Requirement
126
126
  requirements:
127
- - - ! '>='
127
+ - - '>='
128
128
  - !ruby/object:Gem::Version
129
129
  version: '0'
130
130
  requirements: []