Module: TtaTermsApi

Defined in:
lib/tta_terms_api.rb,
lib/tta_terms_api/version.rb

Defined Under Namespace

Classes: Word, WordCritria

Constant Summary collapse

BASE_URL =
"http://word.tta.or.kr/terms/"
VERSION =
"0.0.1"

Class Method Summary collapse

Class Method Details

.html(type, options) ⇒ Object



42
43
44
45
# File 'lib/tta_terms_api.rb', line 42

def self.html(type, options)
  uri = "#{BASE_URL}terms#{type.to_s.capitalize}.jsp?#{options.map{|k,v|"#{k}=#{v}"} * "&"}"
  Nokogiri::HTML(open(uri), nil, "EUC-KR")
end

.list(options) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/tta_terms_api.rb', line 15

def self.list(options)
  html = html(:list, options)
  trs = html.css("#tableWidth tr")
  trs.pop
  trs.map do |tr|
    name = tr.children.first.text.gsub("\n","")
    script = tr.css(".input_size0").attr("onkeydown").value
    script.match(/sendData\(\s*'(.*)',\s*'(.*)',\s*'(.*)',\s*'(.*)',\s*'(.*)',\s*'(.*)',\s*'(.*)',\s*'(.*)',\s*'(.*)',\s*'([^']*)'\s*\)/)
    WordCritria.new name,
      gubun: $1,
      terms_num: $2,
      title: $3,
      title_gubun: $4,
      gubun2: $5,
      terms_num2: $6,
      title2: $7,
      title2_gubun: $8,
      gabora_gubun: $9,
      popular: $10
  end
end

.view(options) ⇒ Object



37
38
39
40
# File 'lib/tta_terms_api.rb', line 37

def self.view(options)
  name, origin, type, _, description = html(:view, options).css("#printSpace font").text.gsub("\t", "").split(/\n/)
  Word.new name, origin, type, description
end