dict 0.2.8 → 0.2.9

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.7)
4
+ dict (0.2.8)
5
5
  nokogiri (~> 1.5.5)
6
6
  slop (~> 3.3.2)
7
7
 
@@ -23,8 +23,9 @@ Search WORD in dict, an open source dictionary aggregator.
23
23
  on '-t', :time=, 'Set timeout in seconds. Default: 300', :as => :int
24
24
  on '-d', :dict=, "Select desired dictionary. Available options: #{Dict.available_dictionaries.join(', ')}"
25
25
  on '-v', :version=, "Information about gem, authors, license", :argument => :optional
26
+ on '-c', :clean=, "Remove examples from translation", :argument => :optional
27
+
26
28
  end
27
- opts
28
29
  end
29
30
 
30
31
  def get_translations(opts, word)
@@ -53,6 +54,20 @@ Search WORD in dict, an open source dictionary aggregator.
53
54
  MSG = "Usage: dict WORD [OPTIONS]\nTry `dict --help for more information.\n"
54
55
  VERSION = "dict version #{Dict::VERSION}\nSearch WORD in dict, an open source dictionary aggregator.\nCopyright (C) 2012 by Mateusz Czerwiński, Michał Podlecki,\nAleksander Gozdek, Rafał Ośko, Jan Borwin, Kosma Dunikowski\nMentors: Grzegorz Kołodziejski, Michał Kwiatkowski\nMade during intership at Ragnarson http://ragnarson.com\nHosted by Shelly Cloud https://shellycloud.com\nLicense: MIT\nHomepage: https://github.com/Ragnarson/dict-gem\nSources dictionaries: http://dict.pl, http://pl.wiktionary.org"
55
56
 
57
+ def clean_translation(opts, word)
58
+ translation = get_translations(opts, word)
59
+ string = String.new
60
+ string = string + word + " : "
61
+ if opts.dict?
62
+ translation[word].each { |x| string << x << ", " }
63
+ else
64
+ Dict.available_dictionaries.each do |x|
65
+ translation[x][word].each { |x| string << x << ", " }
66
+ end
67
+ end
68
+ 2.times { string.chop! }
69
+ string
70
+ end
56
71
 
57
72
  def run
58
73
  begin
@@ -68,16 +83,18 @@ Search WORD in dict, an open source dictionary aggregator.
68
83
  abort(opts.to_s)
69
84
  elsif opts.version?
70
85
  abort(VERSION)
86
+ elsif opts.time?
87
+ if (opts[:time].to_i) == 0
88
+ abort("Wrong time value.")
89
+ else
90
+ puts get_translations(opts, ARGV[0])
91
+ end
71
92
  else
72
93
  if !parameters_valid?
73
94
  abort(MSG)
74
95
  else
75
- if opts.time?
76
- if (opts[:time].to_i) == 0
77
- abort("Wrong time value.")
78
- else
79
- puts get_translations(opts, ARGV[0])
80
- end
96
+ if opts.clean?
97
+ puts clean_translation(opts, ARGV[0])
81
98
  else
82
99
  puts get_translations(opts, ARGV[0])
83
100
  end
data/lib/dict/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dict
2
- VERSION = "0.2.8"
2
+ VERSION = "0.2.9"
3
3
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative './vcr_setup'
4
4
  require 'dict/cli/runner'
5
+ require 'slop'
5
6
 
6
7
  describe "parameters_valid?" do
7
8
  it "should return false if ARGV is empty" do
@@ -22,14 +23,14 @@ describe "parse_parameters" do
22
23
  stub_const("ARGV", ["słowik", "-t", "36"])
23
24
  runner = Dict::CLI::Runner.new
24
25
  opts = runner.parse_parameters
25
- {:help=>nil, :time=>"36", :dict=>nil, :version=>nil}.should == opts.to_hash
26
+ {:help=>nil, :time=>"36", :dict=>nil, :version=>nil, :clean=>nil}.should == opts.to_hash
26
27
  end
27
28
 
28
29
  it "should return Hash for parameters słowik" do
29
30
  stub_const("ARGV", ["słowik"])
30
31
  runner = Dict::CLI::Runner.new
31
32
  opts = runner.parse_parameters
32
- {:help=>nil, :time=>nil, :dict=>nil, :version=>nil}.should == opts.to_hash
33
+ {:help=>nil, :time=>nil, :dict=>nil, :version=>nil, :clean=>nil}.should == opts.to_hash
33
34
  end
34
35
  end
35
36
 
@@ -64,7 +65,7 @@ describe "get_translations" do
64
65
  end
65
66
 
66
67
  describe "CLI::Runner" do
67
- 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"
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"
68
69
  DICT_MSG = "Missing argument. Expected: wiktionary, dictpl"
69
70
  TIME_MSG = "Missing argument. Expected: number of seconds"
70
71
  T_MSG = "Wrong time value."
@@ -105,5 +106,13 @@ describe "CLI::Runner" do
105
106
  runner.run
106
107
  }.to raise_error(SystemExit)
107
108
  end
109
+
110
+ it "should return string when you use --clean parameter" do
111
+ stub_const("ARGV",["słowik","--clean"])
112
+ runner = Dict::CLI::Runner.new
113
+ opts = runner.parse_parameters
114
+ runner.clean_translation(opts, ARGV[0]).should == "słowik : nightingale, nightingale"
115
+ end
116
+
108
117
 
109
118
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dict
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.2.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ authors:
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
- date: 2012-07-17 00:00:00.000000000 Z
17
+ date: 2012-07-18 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: slop