Class: Daijisen::Query
- Inherits:
-
Object
- Object
- Daijisen::Query
- Defined in:
- lib/daijisen.rb
Overview
TODO: Incorporate SHIFT_JS encoding. Only UTF-8 works for now.
Instance Attribute Summary collapse
-
#defs ⇒ Object
Returns the value of attribute defs.
-
#query ⇒ Object
Returns the value of attribute query.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #each ⇒ Object
- #get_raw_html ⇒ Object
-
#initialize(query) ⇒ Query
constructor
A new instance of Query.
Constructor Details
#initialize(query) ⇒ Query
Returns a new instance of Query.
15 16 17 18 19 20 |
# File 'lib/daijisen.rb', line 15 def initialize(query) @query = query @defs = [] @url = "" get_raw_html() end |
Instance Attribute Details
#defs ⇒ Object
Returns the value of attribute defs.
13 14 15 |
# File 'lib/daijisen.rb', line 13 def defs @defs end |
#query ⇒ Object
Returns the value of attribute query.
13 14 15 |
# File 'lib/daijisen.rb', line 13 def query @query end |
#url ⇒ Object
Returns the value of attribute url.
13 14 15 |
# File 'lib/daijisen.rb', line 13 def url @url end |
Instance Method Details
#each ⇒ Object
32 33 34 35 36 |
# File 'lib/daijisen.rb', line 32 def each @defs.each do |d| yield d end end |
#get_raw_html ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/daijisen.rb', line 22 def get_raw_html() @url = "http://dic.yahoo.co.jp/search?stype=0&ei=UTF-8&dtype=2&p=" + CGI::escape(@query) html = Nokogiri::HTML(open(url)) # TODO Configurable and diggable html.css("#DSm1 ol > li").each do |daiji_def| @defs.push(Definition.new(daiji_def)) end end |