tr4n5l4te 0.1.5 → 0.1.6

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
  SHA256:
3
- metadata.gz: 204b74b356e859f4e2eb6495d225307ee7344267785d0e961d7608beb99fdf5e
4
- data.tar.gz: c934a59f87142a43fa9ddc40d4c26e04e73c088a04f916f90e97ce18d2cd2e39
3
+ metadata.gz: 4b2e251b178f16e954b56a61d499486d4e369f66bee5f68ed016ac16270ef7a5
4
+ data.tar.gz: 41894125f771195f11788b26781e1122aa27e39abf8674544aedbd9424d1a19b
5
5
  SHA512:
6
- metadata.gz: b8b01237723dec2ef19e1570f59792701503c769c324dda07da9d950fc85c74897adca11e57507fc5e0531ad9a1202c57814e95f3adc6dd90f66ccd582fe4628
7
- data.tar.gz: 29d9b1c7c921741e2531029f18b1220fe84ad217f52b9f3ab547edfcfbcf97b4936abdc1f130069e4d329f184b91e04089b4cc85141125a0de4e766ad9fd9683
6
+ metadata.gz: 16490612ad1a9683ef67626f15120748e7e6c52f78684cc8a50053ae272e2ee45583ce7880ccc00e4a125b28a16dd0cc9b50bcb3c2f89b1c62843a1ef34a4ff3
7
+ data.tar.gz: ef4b21e7beb0888aee641f23f812690794317fe5da708b6d62b47cdc5fdfa9cbca2c2cd5c1b1f29961bcbab6d5b27b92d2f4922ba22f0916a382863d4ff5cfde
data/.rubocop.yml CHANGED
@@ -1,5 +1,6 @@
1
1
  AllCops:
2
- # Include gemspec and Rakefile
2
+ TargetRubyVersion: 2.4
3
+
3
4
  Include:
4
5
  - '**/*.gemspec'
5
6
  - '**/*.podspec'
@@ -12,9 +13,19 @@ AllCops:
12
13
  - '**/Podfile'
13
14
  - '**/Thorfile'
14
15
  - '**/Vagrantfile'
16
+ - '**/*.rb'
15
17
  Exclude:
18
+ - 'Capfile'
19
+ - 'tmp/**/*'
20
+ - 'log/**/*'
21
+ - 'db/**/*'
16
22
  - 'vendor/**/*'
17
23
  - 'stubs/**/*'
24
+ - 'bin/**/*'
25
+ - 'node_modules/**/*'
26
+ - 'features/step_definitions/*'
27
+ - 'config/deploy.rb'
28
+ - 'config/deploy/**/*.rb'
18
29
 
19
30
  # Checks formatting of special comments
20
31
  CommentAnnotation:
@@ -31,18 +42,9 @@ CommentAnnotation:
31
42
  Style/Documentation:
32
43
  Enabled: false
33
44
 
34
- Style/FileName:
35
- Enabled: false
36
-
37
- Style/AlignParameters:
38
- EnforcedStyle: with_fixed_indentation
39
-
40
45
  Style/RegexpLiteral:
41
46
  Enabled: false
42
47
 
43
- Style/EmptyLinesAroundBlockBody:
44
- Enabled: false
45
-
46
48
  Style/RaiseArgs:
47
49
  Enabled: false
48
50
 
@@ -55,37 +57,102 @@ Style/SignalException:
55
57
  Style/ClassAndModuleChildren:
56
58
  Enabled: false
57
59
 
58
- Style/MultilineMethodCallIndentation:
60
+ Style/TrivialAccessors:
61
+ Enabled: false
62
+
63
+ Style/NumericLiterals:
64
+ Enabled: false
65
+
66
+ Style/EmptyMethod:
67
+ Enabled: false
68
+
69
+ Style/MixinUsage:
70
+ Enabled: false
71
+
72
+ Style/AndOr:
73
+ Enabled: false
74
+
75
+ Style/FrozenStringLiteralComment:
76
+ EnforcedStyle: always
77
+
78
+ # String#format is private now
79
+ Style/FormatString:
80
+ Enabled: false
81
+
82
+ Style/Alias:
83
+ EnforcedStyle: prefer_alias_method
84
+
85
+ ########################################
86
+ # Layout Cops
87
+
88
+ Layout/LineLength:
89
+ Max: 110
90
+ Exclude:
91
+ - 'app/views/**/*'
92
+
93
+ Layout/ParameterAlignment:
94
+ EnforcedStyle: with_fixed_indentation
95
+
96
+ Layout/ArgumentAlignment:
97
+ EnforcedStyle: with_fixed_indentation
98
+
99
+ Layout/AssignmentIndentation:
100
+ Enabled: false
101
+
102
+ Layout/EmptyLinesAroundBlockBody:
103
+ Enabled: false
104
+
105
+ Layout/MultilineMethodCallIndentation:
59
106
  EnforcedStyle: indented
60
107
  IndentationWidth: 4
61
108
 
62
- Style/CaseIndentation:
109
+ Layout/CaseIndentation:
63
110
  Enabled: false
64
111
 
65
- Style/TrivialAccessors:
112
+ Layout/ElseAlignment:
66
113
  Enabled: false
67
114
 
68
- Style/NumericLiterals:
115
+ Layout/EndAlignment:
116
+ EnforcedStyleAlignWith: variable
117
+
118
+ ########################################
119
+ # Naming Cops
120
+
121
+ Naming/FileName:
69
122
  Enabled: false
70
123
 
71
124
  ########################################
72
- # Lint Cops
125
+ # Security Cops
73
126
 
74
- Lint/Eval:
127
+ Security/Eval:
75
128
  Enabled: true
76
129
 
130
+ ########################################
131
+ # Lint Cops
132
+
77
133
  Lint/AssignmentInCondition:
78
134
  Enabled: false
79
135
 
80
136
  ########################################
81
137
  # Metrics Cops
82
138
 
83
- Metrics/LineLength:
84
- Max: 110
85
-
86
139
  Metrics/MethodLength:
87
140
  CountComments: false # count full line comments?
88
141
  Max: 20
89
142
 
90
143
  Metrics/ClassLength:
91
144
  Max: 120
145
+
146
+ Metrics/AbcSize:
147
+ Max: 20
148
+
149
+ Metrics/BlockLength:
150
+ Enabled: true
151
+ Exclude:
152
+ - spec/**/*
153
+
154
+ ########################################
155
+ # Bundler Cops
156
+
157
+ Bundler/OrderedGems:
158
+ Enabled: false
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ *0.1.6* (January 14, 2020)
2
+
3
+ * Fix rubocop violations
4
+ * Upgrade gems to address CVEs
5
+ * Pass `permitted_classes` array to allow new YAML.safe_load to work properly
6
+
1
7
  *0.1.5* (May 06, 2019)
2
8
 
3
9
  * Fixed phantomjs selector, migration to Optimist gem - Thanks @kirylpl
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in tr4n5l4te.gemspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tr4n5l4te (0.1.5)
4
+ tr4n5l4te (0.1.6)
5
5
  capybara (~> 2.6)
6
6
  colored (~> 1)
7
7
  midwire_common (~> 0.1)
@@ -11,8 +11,9 @@ PATH
11
11
  GEM
12
12
  remote: https://rubygems.org/
13
13
  specs:
14
- addressable (2.6.0)
15
- public_suffix (>= 2.0.2, < 4.0)
14
+ addressable (2.7.0)
15
+ public_suffix (>= 2.0.2, < 5.0)
16
+ ast (2.4.0)
16
17
  capybara (2.18.0)
17
18
  addressable
18
19
  mini_mime (>= 0.1.3)
@@ -24,16 +25,20 @@ GEM
24
25
  coderay (1.1.2)
25
26
  colored (1.2)
26
27
  diff-lcs (1.3)
27
- docile (1.3.1)
28
- json (2.2.0)
28
+ docile (1.3.2)
29
+ jaro_winkler (1.5.4)
30
+ json (2.3.0)
29
31
  method_source (0.9.2)
30
32
  midwire_common (0.3.0)
31
33
  thor (~> 0.19)
32
- mini_mime (1.0.1)
34
+ mini_mime (1.0.2)
33
35
  mini_portile2 (2.4.0)
34
- nokogiri (1.10.3)
36
+ nokogiri (1.10.7)
35
37
  mini_portile2 (~> 2.4.0)
36
38
  optimist (3.0.0)
39
+ parallel (1.19.1)
40
+ parser (2.7.0.2)
41
+ ast (~> 2.4.0)
37
42
  poltergeist (1.18.1)
38
43
  capybara (>= 2.1, < 4)
39
44
  cliver (~> 0.3.1)
@@ -43,33 +48,43 @@ GEM
43
48
  method_source (~> 0.9.0)
44
49
  pry-nav (0.3.0)
45
50
  pry (>= 0.9.10, < 0.13.0)
46
- public_suffix (3.0.3)
47
- rack (2.0.7)
51
+ public_suffix (4.0.3)
52
+ rack (2.1.1)
48
53
  rack-test (1.1.0)
49
54
  rack (>= 1.0, < 3)
55
+ rainbow (3.0.0)
50
56
  rake (10.5.0)
51
- rspec (3.8.0)
52
- rspec-core (~> 3.8.0)
53
- rspec-expectations (~> 3.8.0)
54
- rspec-mocks (~> 3.8.0)
55
- rspec-core (3.8.0)
56
- rspec-support (~> 3.8.0)
57
- rspec-expectations (3.8.3)
57
+ rspec (3.9.0)
58
+ rspec-core (~> 3.9.0)
59
+ rspec-expectations (~> 3.9.0)
60
+ rspec-mocks (~> 3.9.0)
61
+ rspec-core (3.9.1)
62
+ rspec-support (~> 3.9.1)
63
+ rspec-expectations (3.9.0)
58
64
  diff-lcs (>= 1.2.0, < 2.0)
59
- rspec-support (~> 3.8.0)
60
- rspec-mocks (3.8.0)
65
+ rspec-support (~> 3.9.0)
66
+ rspec-mocks (3.9.1)
61
67
  diff-lcs (>= 1.2.0, < 2.0)
62
- rspec-support (~> 3.8.0)
63
- rspec-support (3.8.0)
64
- simplecov (0.16.1)
68
+ rspec-support (~> 3.9.0)
69
+ rspec-support (3.9.2)
70
+ rubocop (0.79.0)
71
+ jaro_winkler (~> 1.5.1)
72
+ parallel (~> 1.10)
73
+ parser (>= 2.7.0.1)
74
+ rainbow (>= 2.2.2, < 4.0)
75
+ ruby-progressbar (~> 1.7)
76
+ unicode-display_width (>= 1.4.0, < 1.7)
77
+ ruby-progressbar (1.10.1)
78
+ simplecov (0.17.1)
65
79
  docile (~> 1.1)
66
80
  json (>= 1.8, < 3)
67
81
  simplecov-html (~> 0.10.0)
68
82
  simplecov-html (0.10.2)
69
83
  thor (0.20.3)
70
- websocket-driver (0.7.0)
84
+ unicode-display_width (1.6.0)
85
+ websocket-driver (0.7.1)
71
86
  websocket-extensions (>= 0.1.0)
72
- websocket-extensions (0.1.3)
87
+ websocket-extensions (0.1.4)
73
88
  xpath (3.2.0)
74
89
  nokogiri (~> 1.8)
75
90
 
@@ -81,6 +96,7 @@ DEPENDENCIES
81
96
  pry-nav
82
97
  rake (~> 10.0)
83
98
  rspec (~> 3.0)
99
+ rubocop
84
100
  simplecov (~> 0.11)
85
101
  tr4n5l4te!
86
102
 
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Tr4n5l4te
2
2
 
3
- **Version: 0.1.5**
3
+ **Version: 0.1.6**
4
4
 
5
5
  Use Google Translate without an API key.
6
6
 
@@ -88,6 +88,12 @@ Please be kind or Google is likely to ban your IP address.
88
88
 
89
89
  Bug reports and pull requests are welcome on GitHub at https://github.com/midwire/tr4n5l4te.
90
90
 
91
+ ### Contributors
92
+
93
+ Thanks to all of those who contribute!
94
+
95
+ * @kirylpl - Fixed phantomjs selector, migration to Optimist gem
96
+
91
97
  ## License
92
98
 
93
99
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
 
3
5
  require 'rspec/core/rake_task'
data/exe/translate CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'rubygems'
4
5
  require 'bundler/setup'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'capybara'
2
4
  require 'capybara/poltergeist'
3
5
  require 'yaml'
@@ -16,7 +18,7 @@ module Tr4n5l4te
16
18
 
17
19
  class Agent
18
20
  # rubocop:disable Metrics/LineLength
19
- DEFAULT_UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/601.4.4 (KHTML, like Gecko) Version/9.0.3 Safari/601.4.4'.freeze
21
+ DEFAULT_UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/601.4.4 (KHTML, like Gecko) Version/9.0.3 Safari/601.4.4'
20
22
  # rubocop:enable Metrics/LineLength
21
23
 
22
24
  attr_reader :browser
@@ -27,9 +29,11 @@ module Tr4n5l4te
27
29
  browser.driver.headers = { 'User-Agent' => DEFAULT_UA }
28
30
  end
29
31
 
30
- # rubocop:disable Metrics/AbcSize, Lint/AssignmentInCondition
31
32
  def load_cookies(cookie_file)
32
- return false unless cookie_hash = YAML.load(File.read(cookie_file))
33
+ return false unless cookie_hash = YAML.safe_load(
34
+ File.read(cookie_file), permitted_classes: [Capybara::Poltergeist::Cookie]
35
+ )
36
+
33
37
  browser.driver.clear_cookies
34
38
  cookie_hash.each do |key, cookie_obj|
35
39
  browser.driver.set_cookie(
@@ -43,7 +47,7 @@ module Tr4n5l4te
43
47
  )
44
48
  end
45
49
  end
46
- # rubocop:enable Metrics/AbcSize, Lint/AssignmentInCondition
50
+ # rubocop:enable
47
51
 
48
52
  def store_cookies(cookie_file)
49
53
  FileUtils.mkdir_p(File.dirname(cookie_file))
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Tr4n5l4te
2
4
  class Configuration
3
5
  attr_accessor :timeout
@@ -1,109 +1,113 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Tr4n5l4te
4
+ # rubocop:disable Metrics/ClassLength
2
5
  class Language
6
+ # rubocop:enable Metrics/ClassLength
3
7
  TABLE = {
4
- "af" => "Afrikaans",
5
- "sq" => "Albanian",
6
- "am" => "Amharic",
7
- "ar" => "Arabic",
8
- "hy" => "Armenian",
9
- "az" => "Azerbaijani",
10
- "eu" => "Basque",
11
- "be" => "Belarusian",
12
- "bn" => "Bengali",
13
- "bs" => "Bosnian",
14
- "bg" => "Bulgarian",
15
- "ca" => "Catalan",
16
- "ceb" => "Cebuano",
17
- "ny" => "Chichewa",
18
- "zh-CN" => "Chinese",
19
- "co" => "Corsican",
20
- "hr" => "Croatian",
21
- "cs" => "Czech",
22
- "da" => "Danish",
23
- "nl" => "Dutch",
24
- "en" => "English",
25
- "eo" => "Esperanto",
26
- "et" => "Estonian",
27
- "tl" => "Filipino",
28
- "fi" => "Finnish",
29
- "fr" => "French",
30
- "fy" => "Frisian",
31
- "gl" => "Galician",
32
- "ka" => "Georgian",
33
- "de" => "German",
34
- "el" => "Greek",
35
- "gu" => "Gujarati",
36
- "ht" => "Haitian Creole",
37
- "ha" => "Hausa",
38
- "haw" => "Hawaiian",
39
- "iw" => "Hebrew",
40
- "hi" => "Hindi",
41
- "hmn" => "Hmong",
42
- "hu" => "Hungarian",
43
- "is" => "Icelandic",
44
- "ig" => "Igbo",
45
- "id" => "Indonesian",
46
- "ga" => "Irish",
47
- "it" => "Italian",
48
- "ja" => "Japanese",
49
- "jw" => "Javanese",
50
- "kn" => "Kannada",
51
- "kk" => "Kazakh",
52
- "km" => "Khmer",
53
- "ko" => "Korean",
54
- "ku" => "Kurdish (Kurmanji)",
55
- "ky" => "Kyrgyz",
56
- "lo" => "Lao",
57
- "la" => "Latin",
58
- "lv" => "Latvian",
59
- "lt" => "Lithuanian",
60
- "lb" => "Luxembourgish",
61
- "mk" => "Macedonian",
62
- "mg" => "Malagasy",
63
- "ms" => "Malay",
64
- "ml" => "Malayalam",
65
- "mt" => "Maltese",
66
- "mi" => "Maori",
67
- "mr" => "Marathi",
68
- "mn" => "Mongolian",
69
- "my" => "Myanmar (Burmese)",
70
- "ne" => "Nepali",
71
- "no" => "Norwegian",
72
- "ps" => "Pashto",
73
- "fa" => "Persian",
74
- "pl" => "Polish",
75
- "pt" => "Portuguese",
76
- "pa" => "Punjabi",
77
- "ro" => "Romanian",
78
- "ru" => "Russian",
79
- "sm" => "Samoan",
80
- "gd" => "Scots Gaelic",
81
- "sr" => "Serbian",
82
- "st" => "Sesotho",
83
- "sn" => "Shona",
84
- "sd" => "Sindhi",
85
- "si" => "Sinhala",
86
- "sk" => "Slovak",
87
- "sl" => "Slovenian",
88
- "so" => "Somali",
89
- "es" => "Spanish",
90
- "su" => "Sundanese",
91
- "sw" => "Swahili",
92
- "sv" => "Swedish",
93
- "tg" => "Tajik",
94
- "ta" => "Tamil",
95
- "te" => "Telugu",
96
- "th" => "Thai",
97
- "tr" => "Turkish",
98
- "uk" => "Ukrainian",
99
- "ur" => "Urdu",
100
- "uz" => "Uzbek",
101
- "vi" => "Vietnamese",
102
- "cy" => "Welsh",
103
- "xh" => "Xhosa",
104
- "yi" => "Yiddish",
105
- "yo" => "Yoruba",
106
- "zu" => "Zulu"
8
+ 'af' => 'Afrikaans',
9
+ 'sq' => 'Albanian',
10
+ 'am' => 'Amharic',
11
+ 'ar' => 'Arabic',
12
+ 'hy' => 'Armenian',
13
+ 'az' => 'Azerbaijani',
14
+ 'eu' => 'Basque',
15
+ 'be' => 'Belarusian',
16
+ 'bn' => 'Bengali',
17
+ 'bs' => 'Bosnian',
18
+ 'bg' => 'Bulgarian',
19
+ 'ca' => 'Catalan',
20
+ 'ceb' => 'Cebuano',
21
+ 'ny' => 'Chichewa',
22
+ 'zh-CN' => 'Chinese',
23
+ 'co' => 'Corsican',
24
+ 'hr' => 'Croatian',
25
+ 'cs' => 'Czech',
26
+ 'da' => 'Danish',
27
+ 'nl' => 'Dutch',
28
+ 'en' => 'English',
29
+ 'eo' => 'Esperanto',
30
+ 'et' => 'Estonian',
31
+ 'tl' => 'Filipino',
32
+ 'fi' => 'Finnish',
33
+ 'fr' => 'French',
34
+ 'fy' => 'Frisian',
35
+ 'gl' => 'Galician',
36
+ 'ka' => 'Georgian',
37
+ 'de' => 'German',
38
+ 'el' => 'Greek',
39
+ 'gu' => 'Gujarati',
40
+ 'ht' => 'Haitian Creole',
41
+ 'ha' => 'Hausa',
42
+ 'haw' => 'Hawaiian',
43
+ 'iw' => 'Hebrew',
44
+ 'hi' => 'Hindi',
45
+ 'hmn' => 'Hmong',
46
+ 'hu' => 'Hungarian',
47
+ 'is' => 'Icelandic',
48
+ 'ig' => 'Igbo',
49
+ 'id' => 'Indonesian',
50
+ 'ga' => 'Irish',
51
+ 'it' => 'Italian',
52
+ 'ja' => 'Japanese',
53
+ 'jw' => 'Javanese',
54
+ 'kn' => 'Kannada',
55
+ 'kk' => 'Kazakh',
56
+ 'km' => 'Khmer',
57
+ 'ko' => 'Korean',
58
+ 'ku' => 'Kurdish (Kurmanji)',
59
+ 'ky' => 'Kyrgyz',
60
+ 'lo' => 'Lao',
61
+ 'la' => 'Latin',
62
+ 'lv' => 'Latvian',
63
+ 'lt' => 'Lithuanian',
64
+ 'lb' => 'Luxembourgish',
65
+ 'mk' => 'Macedonian',
66
+ 'mg' => 'Malagasy',
67
+ 'ms' => 'Malay',
68
+ 'ml' => 'Malayalam',
69
+ 'mt' => 'Maltese',
70
+ 'mi' => 'Maori',
71
+ 'mr' => 'Marathi',
72
+ 'mn' => 'Mongolian',
73
+ 'my' => 'Myanmar (Burmese)',
74
+ 'ne' => 'Nepali',
75
+ 'no' => 'Norwegian',
76
+ 'ps' => 'Pashto',
77
+ 'fa' => 'Persian',
78
+ 'pl' => 'Polish',
79
+ 'pt' => 'Portuguese',
80
+ 'pa' => 'Punjabi',
81
+ 'ro' => 'Romanian',
82
+ 'ru' => 'Russian',
83
+ 'sm' => 'Samoan',
84
+ 'gd' => 'Scots Gaelic',
85
+ 'sr' => 'Serbian',
86
+ 'st' => 'Sesotho',
87
+ 'sn' => 'Shona',
88
+ 'sd' => 'Sindhi',
89
+ 'si' => 'Sinhala',
90
+ 'sk' => 'Slovak',
91
+ 'sl' => 'Slovenian',
92
+ 'so' => 'Somali',
93
+ 'es' => 'Spanish',
94
+ 'su' => 'Sundanese',
95
+ 'sw' => 'Swahili',
96
+ 'sv' => 'Swedish',
97
+ 'tg' => 'Tajik',
98
+ 'ta' => 'Tamil',
99
+ 'te' => 'Telugu',
100
+ 'th' => 'Thai',
101
+ 'tr' => 'Turkish',
102
+ 'uk' => 'Ukrainian',
103
+ 'ur' => 'Urdu',
104
+ 'uz' => 'Uzbek',
105
+ 'vi' => 'Vietnamese',
106
+ 'cy' => 'Welsh',
107
+ 'xh' => 'Xhosa',
108
+ 'yi' => 'Yiddish',
109
+ 'yo' => 'Yoruba',
110
+ 'zu' => 'Zulu'
107
111
  }.freeze
108
112
 
109
113
  class << self
@@ -113,6 +117,7 @@ module Tr4n5l4te
113
117
 
114
118
  def ensure_code(string)
115
119
  fail("Invalid language: [#{string}]") unless valid?(string)
120
+
116
121
  code(string) || string
117
122
  end
118
123
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'optimist'
2
4
  require 'colored'
3
5
  require 'fileutils'
@@ -55,7 +57,8 @@ module Tr4n5l4te
55
57
 
56
58
  def from_lang
57
59
  md = File.basename(options[:yaml_file]).match(/^(\w\w)\.yml$/)
58
- raise "Could not determine language from yaml file: '#{options[:yaml_file]}'" unless md
60
+ fail "Could not determine language from yaml file: '#{options[:yaml_file]}'" unless md
61
+
59
62
  md[1]
60
63
  end
61
64
 
@@ -68,31 +71,39 @@ module Tr4n5l4te
68
71
 
69
72
  # rubocop:disable Metrics/MethodLength
70
73
  def collect_args
74
+ # rubocop:disable Metrics/BlockLength
71
75
  Optimist.options do
76
+ # rubocop:enable Metrics/BlockLength
72
77
  opt(
73
78
  :yaml_file,
74
79
  "A YAML locale file - filename determines source language 'en.yml' - English",
75
- type: :string, required: false, short: 'y')
80
+ type: :string, required: false, short: 'y'
81
+ )
76
82
  opt(
77
83
  :lang,
78
84
  'Destination language',
79
- type: :string, required: false, short: 'l')
85
+ type: :string, required: false, short: 'l'
86
+ )
80
87
  opt(
81
88
  :list,
82
89
  'List known languages',
83
- type: :boolean, required: false)
90
+ type: :boolean, required: false
91
+ )
84
92
  opt(
85
93
  :sleep_time,
86
94
  'Sleep time',
87
- type: :integer, default: 2, short: 's')
95
+ type: :integer, default: 2, short: 's'
96
+ )
88
97
  opt(
89
98
  :timeout,
90
99
  'Poltergeist timeout option - default 30',
91
- type: :integer, default: 30, short: 't')
100
+ type: :integer, default: 30, short: 't'
101
+ )
92
102
  opt(
93
103
  :verbose,
94
104
  'Be verbose with output',
95
- type: :boolean, required: false, short: 'v', default: false)
105
+ type: :boolean, required: false, short: 'v', default: false
106
+ )
96
107
  end
97
108
  end
98
109
  # rubocop:enable Metrics/MethodLength
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'open-uri'
2
4
 
3
5
  module Tr4n5l4te
4
6
  class Translator
5
- START_PAGE = 'https://translate.google.com'.freeze
7
+ START_PAGE = 'https://translate.google.com'
6
8
 
7
9
  attr_reader :sleep_time, :agent
8
10
 
@@ -15,6 +17,7 @@ module Tr4n5l4te
15
17
  puts "Translating: #{text}"
16
18
  encoded_text = validate_and_encode(text)
17
19
  return '' if encoded_text == ''
20
+
18
21
  smart_visit(translator_url(encoded_text, from_lang, to_lang))
19
22
  result_box = browser.find('.tlid-translation')
20
23
  result_box.text
@@ -25,8 +28,8 @@ module Tr4n5l4te
25
28
  def validate_and_encode(text)
26
29
  return '' if text.nil?
27
30
  fail "Cannot translate a [#{text.class}]: '#{text}'" unless text.respond_to?(:gsub)
28
- text.strip!
29
- URI.encode(text)
31
+
32
+ CGI.escape(text.strip)
30
33
  end
31
34
 
32
35
  def smart_visit(url)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Tr4n5l4te
2
- VERSION = '0.1.5'.freeze
4
+ VERSION = '0.1.6'.freeze
3
5
  end
data/lib/tr4n5l4te.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'tr4n5l4te/version'
2
4
 
3
5
  require 'midwire_common/string'
data/tr4n5l4te.gemspec CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  lib = File.expand_path('lib', __dir__)
2
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
5
  require 'tr4n5l4te/version'
@@ -22,11 +24,12 @@ Gem::Specification.new do |spec|
22
24
  spec.add_development_dependency 'pry-nav'
23
25
  spec.add_development_dependency 'rake', '~> 10.0'
24
26
  spec.add_development_dependency 'rspec', '~> 3.0'
27
+ spec.add_development_dependency 'rubocop'
25
28
  spec.add_development_dependency 'simplecov', '~> 0.11'
26
29
 
27
30
  spec.add_dependency 'capybara', '~> 2.6'
28
31
  spec.add_dependency 'colored', '~> 1'
29
32
  spec.add_dependency 'midwire_common', '~> 0.1'
30
- spec.add_dependency 'poltergeist', '~> 1.9'
31
33
  spec.add_dependency 'optimist'
34
+ spec.add_dependency 'poltergeist', '~> 1.9'
32
35
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tr4n5l4te
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Blackburn
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-05-06 00:00:00.000000000 Z
11
+ date: 2020-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: simplecov
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -123,33 +137,33 @@ dependencies:
123
137
  - !ruby/object:Gem::Version
124
138
  version: '0.1'
125
139
  - !ruby/object:Gem::Dependency
126
- name: poltergeist
140
+ name: optimist
127
141
  requirement: !ruby/object:Gem::Requirement
128
142
  requirements:
129
- - - "~>"
143
+ - - ">="
130
144
  - !ruby/object:Gem::Version
131
- version: '1.9'
145
+ version: '0'
132
146
  type: :runtime
133
147
  prerelease: false
134
148
  version_requirements: !ruby/object:Gem::Requirement
135
149
  requirements:
136
- - - "~>"
150
+ - - ">="
137
151
  - !ruby/object:Gem::Version
138
- version: '1.9'
152
+ version: '0'
139
153
  - !ruby/object:Gem::Dependency
140
- name: optimist
154
+ name: poltergeist
141
155
  requirement: !ruby/object:Gem::Requirement
142
156
  requirements:
143
- - - ">="
157
+ - - "~>"
144
158
  - !ruby/object:Gem::Version
145
- version: '0'
159
+ version: '1.9'
146
160
  type: :runtime
147
161
  prerelease: false
148
162
  version_requirements: !ruby/object:Gem::Requirement
149
163
  requirements:
150
- - - ">="
164
+ - - "~>"
151
165
  - !ruby/object:Gem::Version
152
- version: '0'
166
+ version: '1.9'
153
167
  description: Use Google Translate without an API key.
154
168
  email:
155
169
  - 87a1779b@opayq.com