dictuby 0.0.8 → 0.0.9

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: dc80c16353302eba29dcfa40f96845266184e259
4
- data.tar.gz: 29dde9645958d0422f3417a8a4ed653e5a2825a5
3
+ metadata.gz: 2aeb4c2f27ea83409959efad3e7f12cbd093a164
4
+ data.tar.gz: 01c419e1786eee5c74842eab5e0b7d9b1f945c09
5
5
  SHA512:
6
- metadata.gz: 0599c314505bc3f8c871a0a1a6b0e09913fcfa4d08bac596e4c48e022d55a750bbc811ac77730ca672a2d3ff567d330ab9a4047ff72ba581c4ce610aafe462ee
7
- data.tar.gz: 9e208ee3b4713f0b7a79b46b675817f23b5ac11bef6630636f754b3f58acc3d19d6bd3390ad8c3718baa8ce2c2bb9633d54817e682e0f0d71cf9918eb31f8ab9
6
+ metadata.gz: 855f378fb801af841b83a93a00917e385290b64ba59e4e719648c7211d0758c16b0c79b8e1d27287ff003c1d101ca938eacbec4858af49f83399ccb91c6eae2a
7
+ data.tar.gz: f4f8eb83d92da3c86baba3ad2eed81c3295a4de5618b24a0ed0b9d7f452853c1fc044d85b1b123b9b7e3991c44fa5059ee0f586f6e45f366a2dc8836fb461909
@@ -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/slovnik_azet_sk'
13
+ require 'dictuby/sources/slovnik_sk'
14
14
  require 'dictuby/sources/slovnik_cz'
15
+ require 'dictuby/sources/dict_cc'
@@ -20,7 +20,7 @@ module Dictuby
20
20
  '--list-dicts',
21
21
  'List available dictionaries'
22
22
  ) do |b|
23
- options[:list] = b
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
@@ -15,6 +15,7 @@ module Dictuby
15
15
  if !@settings
16
16
  @settings = {}
17
17
  set('dictionary', @default_dict)
18
+ set('disabled_sources', [])
18
19
  end
19
20
  end
20
21
 
@@ -1,6 +1,7 @@
1
1
 
2
2
  module Dictuby
3
3
  class OnlineDictionary
4
+ @name = ''
4
5
  @url = ''
5
6
  @dicts = {}
6
7
 
@@ -15,6 +16,10 @@ module Dictuby
15
16
  self.process(page, query)
16
17
  end
17
18
 
19
+ def self.name
20
+ @name
21
+ end
22
+
18
23
  def self.dicts
19
24
  @dicts
20
25
  end
@@ -10,15 +10,22 @@ module Dictuby
10
10
  @config = DictubyConfig.new
11
11
  @args = args
12
12
 
13
- @sources = [SlovnikAzetSK, SlovnikCZ]
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([]) {|r, p| r << p.dicts.keys}
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[:list]
21
- @dicts.each {|d| puts d}
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
- 'ge-cz' => 'gecz.ge',
9
- 'cz-ge' => 'gecz.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
- 'sp-cz' => 'spcz.sp',
15
- 'cz-sp' => 'spcz.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 SlovnikAzetSK < OnlineDictionary
4
- @name = 'slovnik.azet.sk'
3
+ class SlovnikSK < OnlineDictionary
4
+ @name = 'slovnik.sk'
5
5
  @dicts = {
6
6
  'en-sk' => 'anglicko-slovensky',
7
7
  'sk-en' => 'slovensko-anglicky',
8
- 'ge-sk' => 'nemecko-slovensky',
9
- 'sk-ge' => 'slovensko-nemecky',
8
+ 'de-sk' => 'nemecko-slovensky',
9
+ 'sk-de' => 'slovensko-nemecky',
10
10
  'fr-sk' => 'francuzsko-slovensky',
11
11
  'sk-fr' => 'slovensko-francuzsky',
12
- 'sp-sk' => 'spanielsko-slovensky',
13
- 'sk-sp' => 'slovensko-spanielsky',
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
- right = page.xpath(
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.8
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-01 00:00:00.000000000 Z
11
+ date: 2013-09-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Command line online dictionary tool written in ruby
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/slovnik_azet_sk.rb
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://rubygems.org/gems/dictuby
30
+ homepage: https://github.com/simpliplant/dictuby
30
31
  licenses:
31
32
  - MIT
32
33
  metadata: {}