Class: Daijisen::Query

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

Overview

TODO: Incorporate SHIFT_JS encoding. Only UTF-8 works for now.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#defsObject

Returns the value of attribute defs.



13
14
15
# File 'lib/daijisen.rb', line 13

def defs
  @defs
end

#queryObject

Returns the value of attribute query.



13
14
15
# File 'lib/daijisen.rb', line 13

def query
  @query
end

#urlObject

Returns the value of attribute url.



13
14
15
# File 'lib/daijisen.rb', line 13

def url
  @url
end

Instance Method Details

#eachObject



32
33
34
35
36
# File 'lib/daijisen.rb', line 32

def each
  @defs.each do |d|
    yield d
  end
end

#get_raw_htmlObject



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