yandex_dictionary_api 0.2.1 → 0.2.2
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/yandex_dictionary_api.rb +1 -16
- data/lib/yandex_dictionary_api/article.rb +34 -27
- data/lib/yandex_dictionary_api/version.rb +1 -1
- data/spec/spec_yandex_dictionary_api.rb +2 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f018c202409347b65b1fed4dae758b50280eac60
|
4
|
+
data.tar.gz: 98d4435440f9852037edf65be3475334b98636bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 <<
|
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
|
20
|
-
|
21
|
-
|
22
|
-
|
24
|
+
def self.recognize_article(hash)
|
25
|
+
res = Article.new
|
26
|
+
res.read_hash(hash, TEXT)
|
27
|
+
res
|
23
28
|
end
|
24
29
|
|
25
|
-
|
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
|
-
|
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
|
-
|
51
|
+
read_array(value, SYNONYMS)
|
35
52
|
when "mean"
|
36
|
-
|
53
|
+
read_array(value, MEANS)
|
37
54
|
when "ex"
|
38
|
-
|
55
|
+
read_array(value, EXAMPLES)
|
39
56
|
end
|
40
57
|
end
|
41
58
|
end
|
42
59
|
end
|
43
60
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
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,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(
|
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.
|
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-
|
11
|
+
date: 2014-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|