Class: YandexDictionaryApi::Article

Inherits:
Object
  • Object
show all
Defined in:
lib/yandex_dictionary_api/article.rb

Overview

Includes containing of interpretation article, that returns lookup request

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeArticle

Returns a new instance of Article.



16
17
18
19
20
21
22
# File 'lib/yandex_dictionary_api/article.rb', line 16

def initialize()
  @text = ""
  @translations = ""
  @synonyms = ""
  @means = ""
  @examples = ""
end

Instance Attribute Details

#examplesObject

Returns the value of attribute examples.



14
15
16
# File 'lib/yandex_dictionary_api/article.rb', line 14

def examples
  @examples
end

#meansObject

Returns the value of attribute means.



13
14
15
# File 'lib/yandex_dictionary_api/article.rb', line 13

def means
  @means
end

#synonymsObject

Returns the value of attribute synonyms.



12
13
14
# File 'lib/yandex_dictionary_api/article.rb', line 12

def synonyms
  @synonyms
end

#textObject

Returns the value of attribute text.



10
11
12
# File 'lib/yandex_dictionary_api/article.rb', line 10

def text
  @text
end

#translationsObject

Returns the value of attribute translations.



11
12
13
# File 'lib/yandex_dictionary_api/article.rb', line 11

def translations
  @translations
end

Class Method Details

.recognize_article(hash) ⇒ Object



24
25
26
27
28
# File 'lib/yandex_dictionary_api/article.rb', line 24

def self.recognize_article(hash)
  res = Article.new
  res.read_hash(hash, TEXT)
  res
end

Instance Method Details

#read_hash(hash, data_kind) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/yandex_dictionary_api/article.rb', line 30

def read_hash(hash, data_kind)
  hash.each_pair do |key, value|
    unless value.is_a? Array
      txt = value + " "
      case data_kind
      when TEXT
        @text << txt
      when TRANSLATIONS
        @translations << txt
      when SYNONYMS
        @synonyms << txt
      when MEANS
        @means << txt
      when EXAMPLES
        @examples << txt
      end
    else
      case key
      when "tr"
        read_array(value, TRANSLATIONS)
      when "syn"
        read_array(value, SYNONYMS)
      when "mean"
        read_array(value, MEANS)
      when "ex"
        read_array(value, EXAMPLES)
      end
    end
  end
end

#to_hashObject



61
62
63
64
65
66
67
68
69
# File 'lib/yandex_dictionary_api/article.rb', line 61

def to_hash
  res = Hash.new
  res["text"] = @text
  res["translations"] = @translations
  res["synonyms"] = @synonyms
  res["means"] = @means
  res["examples"] = @examples
  res
end