dict 0.2.9 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dict (0.2.8)
4
+ dict (0.3.0)
5
5
  nokogiri (~> 1.5.5)
6
6
  slop (~> 3.3.2)
7
7
 
data/README.md CHANGED
@@ -12,6 +12,8 @@ To search for `WORD`:
12
12
  - `-t` or `--time` - used to set timeout in seconds. Default value: 300
13
13
  - `-d` or `--dict` - used to select desired dictionary
14
14
  - `-v` or `--version` - used to show version, authors, license
15
+ - `-c` or `--clean` - used to delete examples from translation
16
+
15
17
 
16
18
 
17
19
  ## People
@@ -28,8 +30,6 @@ To search for `WORD`:
28
30
  - [Grzegorz Kołodziejczyk](https://github.com/grk)
29
31
  - [Michał Kwiatkowski](https://github.com/mkwiatkowski)
30
32
 
31
- ## Made during intership at Ragnarson
32
- [Ragnarson](http://ragnarson.com/)
33
+ ## Made during internship at [Ragnarson](http://ragnarson.com/)
33
34
 
34
- ## Hosted by
35
- [Shelly Cloud](https://shellycloud.com/)
35
+ ## Hosted by [Shelly Cloud](https://shellycloud.com/)
data/lib/dict/dict.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  require 'dict/wiktionary'
4
- require 'dict/dictpl'
5
4
  require "yaml"
6
5
 
7
6
  module Dict
@@ -30,8 +29,6 @@ module Dict
30
29
  case dictionary
31
30
  when 'wiktionary'
32
31
  Wiktionary.new(word).translate.translations
33
- when 'dictpl'
34
- Dictpl.new(word).translate
35
32
  else Dictionary.message
36
33
  end
37
34
  rescue Dictionary::ConnectError
@@ -46,7 +43,7 @@ module Dict
46
43
 
47
44
  # returns array of currently available dictionaries
48
45
  def available_dictionaries
49
- ['wiktionary', 'dictpl']
46
+ ['wiktionary']
50
47
  end
51
48
  end
52
49
  end
data/lib/dict/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dict
2
- VERSION = "0.2.9"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -3,24 +3,22 @@
3
3
  require 'nokogiri'
4
4
  require 'dict/dictionary'
5
5
 
6
- WIKI_URL = 'http://en.wiktionary.org/wiki/'
7
-
8
6
  module Dict
9
7
  class Wiktionary < Dictionary
10
-
8
+
11
9
  # Returns an Dict::Result object
12
10
  def translate
13
11
  translations.each { |item| @result.add_translation(@result.term, item) }
14
-
12
+
15
13
  @result
16
- end
17
-
14
+ end
15
+
18
16
  def get_html(url)
19
17
  Nokogiri::HTML(open(URI.encode(url)))
20
18
  rescue OpenURI::HTTPError
21
19
  raise Dictionary::ConnectError
22
20
  end
23
-
21
+
24
22
  private
25
23
  def polish?(content)
26
24
  ! /==Polish==/i.match(content).nil?
@@ -30,7 +28,7 @@ module Dict
30
28
  def translations
31
29
  url_pl = "http://en.wiktionary.org/w/index.php?title=#{@word}&action=edit"
32
30
  url_en = "http://pl.wiktionary.org/w/index.php?title=#{@word}&action=edit"
33
-
31
+
34
32
  content_pl = get_html(url_pl).css('textarea#wpTextbox1').first
35
33
  if polish?(content_pl)
36
34
  extract_polish_translations(content_pl)
@@ -38,13 +36,13 @@ module Dict
38
36
  extract_english_translations(get_html(url_en).css('textarea#wpTextbox1').first.content)
39
37
  end
40
38
  end
41
-
39
+
42
40
  # Returns an array containing polish translations.
43
41
  def extract_polish_translations(content)
44
42
  translations = /Noun[^\{]+\{\{(?:head\|pl|pl\-noun)[^#]+#\s*\[\[([^\n]+)/.match(content)
45
43
  translations = (translations && translations[1].gsub(/\[|\]/,'').split(', ')) || []
46
44
  end
47
-
45
+
48
46
  # Returns an array containing english translations.
49
47
  def extract_english_translations(content)
50
48
  translations_block = /język\s+angielski(?:.|\n)+\{\{znaczenia\}\}(.|\n)+(?:\{\{odmiana){1,}/.match(content)
@@ -57,7 +55,7 @@ module Dict
57
55
  translations.delete_if(&:empty?)
58
56
  translations ||= []
59
57
  end
60
-
58
+
61
59
  def get_examples(content, polish = true)
62
60
  # todo
63
61
  end
@@ -37,21 +37,21 @@ end
37
37
 
38
38
  describe "get_translations" do
39
39
  it "should return results from wiktionary and dictpl for word 'słowik'" do
40
- VCR.use_cassette('translations_slownik_cassette') do
40
+ VCR.use_cassette('translations_slownik_cassette') do
41
41
  stub_const("ARGV", ["słowik"])
42
42
  runner = Dict::CLI::Runner.new
43
43
  opts = runner.parse_parameters
44
- runner.get_translations(opts, "słowik").should == {"wiktionary"=>{"słowik"=>["nightingale"]}, "dictpl"=>{"słowik"=>["nightingale"], "słowik białobrewy; Luscinia indicus; Tarsiger indicus (gatunek ptaka)"=>["white-browed bush-robin"], "słowik białosterny; Luscinia pectoralis (gatunek ptaka)"=>["Himalayan rubythroat", "white-tailed rubythroat"], "słowik chiński; pekińczyk żółty; Leiothrix lutea"=>["Pekin robin", "red-billed leiothrix"], "słowik chiński; pekińczyk żółty; pekińczyk koralodzioby; Leiothrix lutea"=>["Peking robin"], "słowik czarnogardły; Luscinia obscura"=>["black-throated blue robin"], "słowik himalajski; Luscinia brunnea (gatunek ptaka)"=>["Indian blue chat", "Indian blue robin"], "słowik modry; Luscinia cyane"=>["Siberian blue robin"], "słowik obrożny; Luscinia johnstoniae; Tarsiger johnstoniae (gatunek ptaka)"=>["collared bush-robin"]}}
45
- end
44
+ runner.get_translations(opts, "słowik").should == {"wiktionary"=>{"słowik"=>["nightingale"]}}
45
+ end
46
46
  end
47
47
 
48
48
  it "should return results from selected dictionary for word 'słowik'" do
49
- VCR.use_cassette('translations_slownik_cassette') do
50
- stub_const("ARGV", ["słowik", "-d", "dictpl"])
49
+ VCR.use_cassette('translations_slownik_cassette') do
50
+ stub_const("ARGV", ["słowik", "-d", "wiktionary"])
51
51
  runner = Dict::CLI::Runner.new
52
52
  opts = runner.parse_parameters
53
- runner.get_translations(opts, "słowik").should == {"słowik"=>["nightingale"], "słowik białobrewy; Luscinia indicus; Tarsiger indicus (gatunek ptaka)"=>["white-browed bush-robin"], "słowik białosterny; Luscinia pectoralis (gatunek ptaka)"=>["Himalayan rubythroat", "white-tailed rubythroat"], "słowik chiński; pekińczyk żółty; Leiothrix lutea"=>["Pekin robin", "red-billed leiothrix"], "słowik chiński; pekińczyk żółty; pekińczyk koralodzioby; Leiothrix lutea"=>["Peking robin"], "słowik czarnogardły; Luscinia obscura"=>["black-throated blue robin"], "słowik himalajski; Luscinia brunnea (gatunek ptaka)"=>["Indian blue chat", "Indian blue robin"], "słowik modry; Luscinia cyane"=>["Siberian blue robin"], "słowik obrożny; Luscinia johnstoniae; Tarsiger johnstoniae (gatunek ptaka)"=>["collared bush-robin"]}
54
- end
53
+ runner.get_translations(opts, "słowik").should == {"słowik"=>["nightingale"]}
54
+ end
55
55
  end
56
56
 
57
57
  it "should return timeout message for word słowik and -t 5" do
@@ -65,8 +65,8 @@ describe "get_translations" do
65
65
  end
66
66
 
67
67
  describe "CLI::Runner" do
68
- HELP_MSG = "Usage: dict WORD [OPTIONS]\nSearch WORD in dict, an open source dictionary aggregator.\n\n -h, --help Display this help message\n -t, --time Set timeout in seconds. Default: 300\n -d, --dict Select desired dictionary. Available options: wiktionary, dictpl\n -v, --version Information about gem, authors, license\n -c, --clean Remove examples from translation"
69
- DICT_MSG = "Missing argument. Expected: wiktionary, dictpl"
68
+ HELP_MSG = "Usage: dict WORD [OPTIONS]\nSearch WORD in dict, an open source dictionary aggregator.\n\n -h, --help Display this help message\n -t, --time Set timeout in seconds. Default: 300\n -d, --dict Select desired dictionary. Available options: wiktionary\n -v, --version Information about gem, authors, license\n -c, --clean Remove examples from translation"
69
+ DICT_MSG = "Missing argument. Expected: wiktionary"
70
70
  TIME_MSG = "Missing argument. Expected: number of seconds"
71
71
  T_MSG = "Wrong time value."
72
72
 
@@ -111,8 +111,8 @@ describe "CLI::Runner" do
111
111
  stub_const("ARGV",["słowik","--clean"])
112
112
  runner = Dict::CLI::Runner.new
113
113
  opts = runner.parse_parameters
114
- runner.clean_translation(opts, ARGV[0]).should == "słowik : nightingale, nightingale"
114
+ runner.clean_translation(opts, ARGV[0]).should == "słowik : nightingale"
115
115
  end
116
116
 
117
-
117
+
118
118
  end
@@ -10,19 +10,16 @@ describe Dict do
10
10
  arr.size.should_not == 0
11
11
  end
12
12
 
13
- it "should return array of available services, which contains wiktionary and dictpl" do
14
- Dict.available_dictionaries.should == ['wiktionary', 'dictpl']
15
- end
16
-
17
- it "should return hash with translations from all dictionaries" do
13
+ it "should return array of available services, which contains wiktionary and dictpl" do
14
+ Dict.available_dictionaries.should == ['wiktionary']
15
+ end
16
+
17
+ it "should return hash with translations from all dictionaries" do
18
18
  wiktionary = stub(:translate => stub(:translations => {'WORD' => 'WIKTIONARY_RESULTS'}))
19
- Dict::Wiktionary.should_receive(:new).with('WORD').and_return(wiktionary)
20
-
21
- dictpl = stub(:translate =>{'WORD' => 'DICTPL_RESULTS'})
22
- Dict::Dictpl.should_receive(:new).with('WORD').and_return(dictpl)
23
-
19
+ Dict::Wiktionary.should_receive(:new).with('WORD').and_return(wiktionary)
20
+
24
21
  results = Dict::get_all_dictionaries_translations('WORD')
25
- results.should == {'dictpl' => {'WORD' => 'DICTPL_RESULTS'}, 'wiktionary' => {'WORD' => 'WIKTIONARY_RESULTS'}}
22
+ results.should == {'wiktionary' => {'WORD' => 'WIKTIONARY_RESULTS'}}
26
23
  end
27
24
 
28
25
  it "should return whatever Wiktionary returns embedded in a hash" do
@@ -30,10 +27,4 @@ describe Dict do
30
27
  Dict::Wiktionary.should_receive(:new).with('WORD').and_return(wiktionary)
31
28
  Dict.get_single_dictionary_translations('WORD', 'wiktionary').should == 'WIKTIONARY_RESULTS'
32
29
  end
33
-
34
- it "should return whatever Dictpl returns embedded in a hash" do
35
- dictpl = stub(:translate => 'DICTPL_RESULTS')
36
- Dict::Dictpl.should_receive(:new).with('WORD').and_return(dictpl)
37
- Dict.get_single_dictionary_translations('WORD', 'dictpl').should == 'DICTPL_RESULTS'
38
- end
39
30
  end