Class: JishoHelper::JishoJisho

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(keyword) ⇒ JishoJisho

Returns a new instance of JishoJisho.



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/jisho_helper/jisho_jisho.rb', line 4

def initialize keyword
  word_url = jisho_url keyword
  json_data = JSON.parse(get_info(word_url))

  unless json_data['data'].empty?
    @kanji = json_data['data'][0]['japanese'][0]['word']
    @kana = json_data['data'][0]['japanese'][0]['reading']
  else
    @kanji = 'N/A'
    @kana = 'N/A'
  end
end

Instance Attribute Details

#kanaObject (readonly)

Returns the value of attribute kana.



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

def kana
  @kana
end

#kanjiObject (readonly)

Returns the value of attribute kanji.



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

def kanji
  @kanji
end

Instance Method Details

#get_info(url) ⇒ Object



17
18
19
# File 'lib/jisho_helper/jisho_jisho.rb', line 17

def get_info url
  json_data = Nokogiri::HTML(open(url).read)
end