Class: JishoHelper::JishoTere

Inherits:
Object
  • Object
show all
Defined in:
lib/jisho_helper/jisho_tere.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(keyword, japanese) ⇒ JishoTere

Returns a new instance of JishoTere.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/jisho_helper/jisho_tere.rb', line 4

def initialize keyword, japanese
  if japanese 
    return @entry = 'N/A'
  else
    id_url = tere_url keyword
    id_doc = parse_xml id_url
    unless  id_doc.search('ItemID').empty?
      id =  id_doc.search('ItemID').first.inner_text 
      unless id.to_i == 0
        word_url = tere_id_url id
        word_doc = parse_xml word_url
        word = word_doc.search('Body').children[1].text rescue nil
        word.gsub!(/(\r\n|\r|\n|\t|\s)/, '')
        @entry = word
      end
    else
      @entry = "N/A"
    end
  end
end

Instance Attribute Details

#entryObject (readonly)

Returns the value of attribute entry.



2
3
4
# File 'lib/jisho_helper/jisho_tere.rb', line 2

def entry
  @entry
end