Class: JishoHelper::JishoJisho
- Inherits:
-
Object
- Object
- JishoHelper::JishoJisho
- Defined in:
- lib/jisho_helper/jisho_jisho.rb
Instance Attribute Summary collapse
-
#kana ⇒ Object
readonly
Returns the value of attribute kana.
-
#kanji ⇒ Object
readonly
Returns the value of attribute kanji.
Instance Method Summary collapse
- #get_info(url) ⇒ Object
-
#initialize(keyword) ⇒ JishoJisho
constructor
A new instance of JishoJisho.
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
#kana ⇒ Object (readonly)
Returns the value of attribute kana.
2 3 4 |
# File 'lib/jisho_helper/jisho_jisho.rb', line 2 def kana @kana end |
#kanji ⇒ Object (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 |