Class: JishoHelper::JishoBreen
- Inherits:
-
Object
- Object
- JishoHelper::JishoBreen
- Defined in:
- lib/jisho_helper/jisho_breen.rb
Instance Attribute Summary collapse
-
#example1 ⇒ Object
readonly
Returns the value of attribute example1.
-
#example2 ⇒ Object
readonly
Returns the value of attribute example2.
Instance Method Summary collapse
- #assign_examples(example) ⇒ Object
- #get_info(url) ⇒ Object
-
#initialize(keyword) ⇒ JishoBreen
constructor
A new instance of JishoBreen.
Constructor Details
#initialize(keyword) ⇒ JishoBreen
Returns a new instance of JishoBreen.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/jisho_helper/jisho_breen.rb', line 4 def initialize keyword enc_jp = keyword.encode(Encoding::EucJP) url_safe_word = URI.escape(enc_jp) word_url = breen_url url_safe_word raw_example = get_info(word_url) example = raw_example.search('pre').children[0] unless example.nil? assign_examples example.text else @example1 = 'N/A' @example2 = 'N/A' end end |
Instance Attribute Details
#example1 ⇒ Object (readonly)
Returns the value of attribute example1.
2 3 4 |
# File 'lib/jisho_helper/jisho_breen.rb', line 2 def example1 @example1 end |
#example2 ⇒ Object (readonly)
Returns the value of attribute example2.
2 3 4 |
# File 'lib/jisho_helper/jisho_breen.rb', line 2 def example2 @example2 end |
Instance Method Details
#assign_examples(example) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/jisho_helper/jisho_breen.rb', line 19 def assign_examples example example = example.split example.each_with_index do |letter, i| break if !@example1.nil? && !@example2.nil? if letter == "A:" if i == 0 @example1 = example[i+1] else @example2 = example[i+1] end end end end |
#get_info(url) ⇒ Object
33 34 35 |
# File 'lib/jisho_helper/jisho_breen.rb', line 33 def get_info url json_data = Nokogiri::HTML(open(url).read) end |