dictuby 0.0.8 → 0.0.9
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 +4 -4
- data/lib/dictuby.rb +2 -1
- data/lib/dictuby/args_parser.rb +25 -1
- data/lib/dictuby/config.rb +1 -0
- data/lib/dictuby/online_dictionary.rb +5 -0
- data/lib/dictuby/runner.rb +38 -4
- data/lib/dictuby/sources/dict_cc.rb +35 -0
- data/lib/dictuby/sources/slovnik_cz.rb +4 -4
- data/lib/dictuby/sources/{slovnik_azet_sk.rb → slovnik_sk.rb} +8 -10
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2aeb4c2f27ea83409959efad3e7f12cbd093a164
|
4
|
+
data.tar.gz: 01c419e1786eee5c74842eab5e0b7d9b1f945c09
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 855f378fb801af841b83a93a00917e385290b64ba59e4e719648c7211d0758c16b0c79b8e1d27287ff003c1d101ca938eacbec4858af49f83399ccb91c6eae2a
|
7
|
+
data.tar.gz: f4f8eb83d92da3c86baba3ad2eed81c3295a4de5618b24a0ed0b9d7f452853c1fc044d85b1b123b9b7e3991c44fa5059ee0f586f6e45f366a2dc8836fb461909
|
data/lib/dictuby.rb
CHANGED
@@ -10,5 +10,6 @@ require 'dictuby/runner'
|
|
10
10
|
require 'dictuby/args_parser'
|
11
11
|
require 'dictuby/config'
|
12
12
|
require 'dictuby/online_dictionary'
|
13
|
-
require 'dictuby/sources/
|
13
|
+
require 'dictuby/sources/slovnik_sk'
|
14
14
|
require 'dictuby/sources/slovnik_cz'
|
15
|
+
require 'dictuby/sources/dict_cc'
|
data/lib/dictuby/args_parser.rb
CHANGED
@@ -20,7 +20,7 @@ module Dictuby
|
|
20
20
|
'--list-dicts',
|
21
21
|
'List available dictionaries'
|
22
22
|
) do |b|
|
23
|
-
options[:
|
23
|
+
options[:list_dicts] = b
|
24
24
|
end
|
25
25
|
|
26
26
|
o.on(
|
@@ -38,6 +38,30 @@ module Dictuby
|
|
38
38
|
) do |d|
|
39
39
|
options[:set] = d
|
40
40
|
end
|
41
|
+
|
42
|
+
o.on(
|
43
|
+
'-a',
|
44
|
+
'--list-sources',
|
45
|
+
'List available sources'
|
46
|
+
) do |b|
|
47
|
+
options[:list_sources] = b
|
48
|
+
end
|
49
|
+
|
50
|
+
o.on(
|
51
|
+
'-e SOURCE_NAME',
|
52
|
+
'--enable-source SOURCE_NAME',
|
53
|
+
'Enable source with specified name'
|
54
|
+
) do |s|
|
55
|
+
options[:enable] = s
|
56
|
+
end
|
57
|
+
|
58
|
+
o.on(
|
59
|
+
'-d SOURCE_NAME',
|
60
|
+
'--disable-source SOURCE_NAME',
|
61
|
+
'Enable source with specified name'
|
62
|
+
) do |s|
|
63
|
+
options[:disable] = s
|
64
|
+
end
|
41
65
|
o.on('QUERY') {}
|
42
66
|
o.parse!
|
43
67
|
end
|
data/lib/dictuby/config.rb
CHANGED
data/lib/dictuby/runner.rb
CHANGED
@@ -10,15 +10,22 @@ module Dictuby
|
|
10
10
|
@config = DictubyConfig.new
|
11
11
|
@args = args
|
12
12
|
|
13
|
-
@sources = [
|
13
|
+
@sources = [SlovnikSK, SlovnikCZ, DictCC]
|
14
|
+
@source_names = @sources.inject([]) {|r,s| r << s.name}
|
15
|
+
@dsources = @config.get('disabled_sources') || []
|
14
16
|
|
15
|
-
@dicts = @sources.inject([])
|
17
|
+
@dicts = @sources.inject([]) do |r, s|
|
18
|
+
r << s.dicts.keys unless @dsources.include?(s.name)
|
19
|
+
r
|
20
|
+
end
|
16
21
|
@dicts.flatten!.sort!
|
17
22
|
end
|
18
23
|
|
19
24
|
def run
|
20
|
-
if @options[:
|
21
|
-
@dicts.
|
25
|
+
if @options[:list_dicts]
|
26
|
+
@dicts.each_slice(6) do |d1, d2, d3, d4, d5, d6|
|
27
|
+
puts "#{d1} #{d2} #{d3} #{d4} #{d5} #{d6}"
|
28
|
+
end
|
22
29
|
elsif @options[:set]
|
23
30
|
if @dicts.include?(@options[:set])
|
24
31
|
@config.set('dictionary', @options[:set])
|
@@ -27,6 +34,33 @@ module Dictuby
|
|
27
34
|
end
|
28
35
|
elsif @options[:get]
|
29
36
|
puts @config.get('dictionary')
|
37
|
+
elsif @options[:list_sources]
|
38
|
+
@source_names.each do |name|
|
39
|
+
puts "%{name} - %{status}" % {
|
40
|
+
:name => name,
|
41
|
+
:status => @dsources.include?(name) ? 'Disabled' : 'Enabled'
|
42
|
+
}
|
43
|
+
end
|
44
|
+
elsif @options[:enable]
|
45
|
+
if !@source_names.include?(@options[:enable])
|
46
|
+
puts 'Invalid source'
|
47
|
+
elsif @dsources.include?(@options[:enable])
|
48
|
+
@dsources.delete(@options[:enable])
|
49
|
+
@config.set('disabled_sources', @dsources)
|
50
|
+
puts 'Source enabled'
|
51
|
+
else
|
52
|
+
puts 'Source already enabled'
|
53
|
+
end
|
54
|
+
elsif @options[:disable]
|
55
|
+
if !@source_names.include?(@options[:disable])
|
56
|
+
puts 'Invalid source'
|
57
|
+
elsif @dsources.include?(@options[:disable])
|
58
|
+
puts 'Source already disabled'
|
59
|
+
else
|
60
|
+
@dsources << @options[:disable]
|
61
|
+
@config.set('disabled_sources', @dsources)
|
62
|
+
puts "Source disabled"
|
63
|
+
end
|
30
64
|
else
|
31
65
|
if @args.size == 1
|
32
66
|
dict, query = @config.get('dictionary'), @args[0]
|
@@ -0,0 +1,35 @@
|
|
1
|
+
|
2
|
+
module Dictuby
|
3
|
+
class DictCC < OnlineDictionary
|
4
|
+
@name = 'dict.cc'
|
5
|
+
@dicts = {
|
6
|
+
'en-es' => 'en-es',
|
7
|
+
'es-en' => 'es-en',
|
8
|
+
'en-de' => 'en-de',
|
9
|
+
'de-en' => 'de-en',
|
10
|
+
'en-fr' => 'en-fr',
|
11
|
+
'fr-en' => 'fr-en',
|
12
|
+
'en-it' => 'en-it',
|
13
|
+
'it-en' => 'it-en',
|
14
|
+
'en-fi' => 'en-fi',
|
15
|
+
'fi-en' => 'fi-en',
|
16
|
+
}
|
17
|
+
@url = 'http://%{dict}.dict.cc/?s=%{query}'
|
18
|
+
|
19
|
+
def self.process(page, query)
|
20
|
+
page.xpath(
|
21
|
+
'//tr[starts-with(@id, "tr")]'
|
22
|
+
).inject([]) do |result, tr|
|
23
|
+
tds = tr.xpath('td[@dir="ltr"]')
|
24
|
+
|
25
|
+
left = tds[0].xpath('a')[0].text.normalize
|
26
|
+
right = tds[1].xpath('a')[0].text.normalize
|
27
|
+
|
28
|
+
return result if left != query && right != query
|
29
|
+
|
30
|
+
result << left == query ? right : left
|
31
|
+
result
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -5,14 +5,14 @@ module Dictuby
|
|
5
5
|
@dicts = {
|
6
6
|
'en-cz' => 'encz.en',
|
7
7
|
'cz-en' => 'encz.cz',
|
8
|
-
'
|
9
|
-
'cz-
|
8
|
+
'de-cz' => 'gecz.ge',
|
9
|
+
'cz-de' => 'gecz.cz',
|
10
10
|
'fr-cz' => 'frcz.fr',
|
11
11
|
'cz-fr' => 'frcz.cz',
|
12
12
|
'it-cz' => 'itcz.it',
|
13
13
|
'cz-it' => 'itcz.cz',
|
14
|
-
'
|
15
|
-
'cz-
|
14
|
+
'es-cz' => 'spcz.sp',
|
15
|
+
'cz-es' => 'spcz.cz',
|
16
16
|
}
|
17
17
|
@url = 'http://slovnik.cz/bin/mld.fpl?vcb=%{query}&dictdir=%{dict}&lines=30&js=0'
|
18
18
|
|
@@ -1,16 +1,16 @@
|
|
1
1
|
|
2
2
|
module Dictuby
|
3
|
-
class
|
4
|
-
@name = 'slovnik.
|
3
|
+
class SlovnikSK < OnlineDictionary
|
4
|
+
@name = 'slovnik.sk'
|
5
5
|
@dicts = {
|
6
6
|
'en-sk' => 'anglicko-slovensky',
|
7
7
|
'sk-en' => 'slovensko-anglicky',
|
8
|
-
'
|
9
|
-
'sk-
|
8
|
+
'de-sk' => 'nemecko-slovensky',
|
9
|
+
'sk-de' => 'slovensko-nemecky',
|
10
10
|
'fr-sk' => 'francuzsko-slovensky',
|
11
11
|
'sk-fr' => 'slovensko-francuzsky',
|
12
|
-
'
|
13
|
-
'sk-
|
12
|
+
'es-sk' => 'spanielsko-slovensky',
|
13
|
+
'sk-es' => 'slovensko-spanielsky',
|
14
14
|
'hu-sk' => 'madarsko-slovensky',
|
15
15
|
'sk-hu' => 'slovensko-madarsky',
|
16
16
|
'it-sk' => 'taliansko-slovensky',
|
@@ -23,16 +23,14 @@ module Dictuby
|
|
23
23
|
def self.process(page, query)
|
24
24
|
query = query.normalize
|
25
25
|
left = page.xpath('//table[1]//span')[0].text rescue nil
|
26
|
-
left.normalize!
|
26
|
+
left.normalize! unless left.nil?
|
27
27
|
return [] unless left == query
|
28
28
|
|
29
|
-
|
29
|
+
page.xpath(
|
30
30
|
'//table[1]//tr/td[@class="do"]/span'
|
31
31
|
).inject([]) {
|
32
32
|
|r, e| r << e.text
|
33
33
|
}
|
34
|
-
|
35
|
-
right
|
36
34
|
end
|
37
35
|
end
|
38
36
|
end
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dictuby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rene Klacan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: Command line online dictionary tool written in
|
13
|
+
description: Command line online dictionary tool written in Ruby
|
14
14
|
email: rene.klacan@gmail.com
|
15
15
|
executables:
|
16
16
|
- dictuby
|
@@ -20,13 +20,14 @@ files:
|
|
20
20
|
- lib/dictuby.rb
|
21
21
|
- lib/dictuby/string.rb
|
22
22
|
- lib/dictuby/online_dictionary.rb
|
23
|
-
- lib/dictuby/sources/
|
23
|
+
- lib/dictuby/sources/slovnik_sk.rb
|
24
24
|
- lib/dictuby/sources/slovnik_cz.rb
|
25
|
+
- lib/dictuby/sources/dict_cc.rb
|
25
26
|
- lib/dictuby/config.rb
|
26
27
|
- lib/dictuby/args_parser.rb
|
27
28
|
- lib/dictuby/runner.rb
|
28
29
|
- bin/dictuby
|
29
|
-
homepage: https://
|
30
|
+
homepage: https://github.com/simpliplant/dictuby
|
30
31
|
licenses:
|
31
32
|
- MIT
|
32
33
|
metadata: {}
|