yandex_dictionary_api 0.2.1 → 0.2.2

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: 34e76bdb7d5419b0e4c976f955e77d104c8eab85
4
- data.tar.gz: 7a3360ce89a10f218b78de0c9e64c1631419977d
3
+ metadata.gz: f018c202409347b65b1fed4dae758b50280eac60
4
+ data.tar.gz: 98d4435440f9852037edf65be3475334b98636bc
5
5
  SHA512:
6
- metadata.gz: edae715beae7c2594c3d9e2ea3c805c0cf02f2649425de32cfd21aec498ded1b8342acc4594c046d6a61a931aec39e8620b10ba4161aa8d929e6c7133b7cddae
7
- data.tar.gz: e9670c646adfee781b57c28416f8c4e5df303b72289d75a6099d8aefd8bcc08226964cd80d385a0c041a2f7ed5ce0acab9005dba184ef00a7e6f3adc338be614
6
+ metadata.gz: b8783ebad70308b0115e511b8bca52ab3ff065170d031f2598817e8626dfc93211a50b56d95dbe13d47fd69f46dd61990d2bab2bb2326ffe77312f9ca96b42ae
7
+ data.tar.gz: 6f7937130e173bbdb1997c082848c65f443cb0d02ce0f8eb5f61f578d21dd24136083de0aa2c451cb1df0bbfa061bf8aba71f5b589819b026f91c97ab581ddf8
@@ -62,25 +62,10 @@ module YandexDictionaryApi
62
62
  def read_lookup_response(hash)
63
63
  res = Array.new
64
64
  hash["def"].each do |hash|
65
- res << read_response_hash(hash)
65
+ res << Article::recognize_article(hash)
66
66
  end
67
67
  res
68
68
  end
69
69
 
70
- def read_response_hash(hash)
71
- res = Article.new
72
- hash.each_pair do |key, value|
73
- unless value.is_a? Array
74
- res.text = res.text << value << " "
75
- else
76
- if key == "tr"
77
- res.recognize_translation(value)
78
- else
79
- raise StandardError.new("Unknown format of response message. Please, contact the developer.")
80
- end
81
- end
82
- end
83
- res
84
- end
85
70
  end
86
71
  end
@@ -1,5 +1,10 @@
1
1
  module YandexDictionaryApi
2
-
2
+ TEXT = 1.freeze
3
+ TRANSLATIONS = 2.freeze
4
+ SYNONYMS = 3.freeze
5
+ MEANS = 4.freeze
6
+ EXAMPLES = 5.freeze
7
+
3
8
  # Includes containing of interpretation article, that returns lookup request
4
9
  class Article
5
10
  attr_accessor :text
@@ -16,47 +21,49 @@ module YandexDictionaryApi
16
21
  @examples = ""
17
22
  end
18
23
 
19
- def recognize_translation(array)
20
- array.each do |hash|
21
- read_hash(hash)
22
- end
24
+ def self.recognize_article(hash)
25
+ res = Article.new
26
+ res.read_hash(hash, TEXT)
27
+ res
23
28
  end
24
29
 
25
- protected
26
-
27
- def read_hash(hash)
30
+ def read_hash(hash, data_kind)
28
31
  hash.each_pair do |key, value|
29
32
  unless value.is_a? Array
30
- @translations << value << " "
33
+ txt = value + " "
34
+ case data_kind
35
+ when TEXT
36
+ @text << txt
37
+ when TRANSLATIONS
38
+ @translations << txt
39
+ when SYNONYMS
40
+ @synonyms << txt
41
+ when MEANS
42
+ @means << txt
43
+ when EXAMPLES
44
+ @examples << txt
45
+ end
31
46
  else
32
47
  case key
48
+ when "tr"
49
+ read_array(value, TRANSLATIONS)
33
50
  when "syn"
34
- @synonyms << read_attr_string(value)
51
+ read_array(value, SYNONYMS)
35
52
  when "mean"
36
- @means << read_attr_string(value)
53
+ read_array(value, MEANS)
37
54
  when "ex"
38
- @examples << read_attr_string(value)
55
+ read_array(value, EXAMPLES)
39
56
  end
40
57
  end
41
58
  end
42
59
  end
43
60
 
44
- def read_attr_string(list)
45
- str_res = ""
46
- if list.is_a? Array
47
- list.each do |hash|
48
- str_res << read_attr_string(hash)
49
- end
50
- return str_res
51
- end
52
- list.each_pair do |key, value|
53
- if value.is_a? Array
54
- str_res << read_attr_string(value)
55
- else
56
- str_res << "#{value}" << " "
57
- end
61
+ protected
62
+
63
+ def read_array(array, data_kind)
64
+ array.each do |hash|
65
+ read_hash(hash, data_kind)
58
66
  end
59
- str_res
60
67
  end
61
68
 
62
69
  end
@@ -1,3 +1,3 @@
1
1
  module YandexDictionaryApi
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -1,9 +1,10 @@
1
1
  require "spec_helper"
2
+ require "/home/user/git/dictionary/config/initializers/constants"
2
3
 
3
4
  describe YandexDictionaryApi do
4
5
 
5
6
  before do
6
- $interface = YandexDictionaryApi::ApiInterface.new(ENV["KEY"])
7
+ $interface = YandexDictionaryApi::ApiInterface.new(Constants::API_KEY)
7
8
  end
8
9
 
9
10
  it "should return a list of supported languages" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yandex_dictionary_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - IronSerj
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-05 00:00:00.000000000 Z
11
+ date: 2014-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler