Module: TtaTermsApi
- Defined in:
- lib/tta_terms_api.rb,
lib/tta_terms_api/version.rb
Defined Under Namespace
Classes: Word, WordCriteria
Constant Summary collapse
- BASE_URL =
"http://word.tta.or.kr/terms/"- STORE =
Moneta.new(:File, :dir => 'tmp')
- VERSION =
"0.0.3"
Class Method Summary collapse
Class Method Details
.html(type, options) ⇒ Object
44 45 46 47 48 |
# File 'lib/tta_terms_api.rb', line 44 def self.html(type, ) uri = "#{BASE_URL}terms#{type.to_s.capitalize}.jsp?#{options.map{|k,v|"#{k}=#{v}"} * "&"}" html = STORE.fetch(uri) { STORE[uri] = open(uri).read } Nokogiri::HTML(html, nil, "EUC-KR") end |
.list(options) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/tta_terms_api.rb', line 17 def self.list() html = html(:list, ) 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*\)/) WordCriteria.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
39 40 41 42 |
# File 'lib/tta_terms_api.rb', line 39 def self.view() name, origin, type, similar, description = html(:view, ).css("#printSpace font").text.gsub("\t", "").split(/\n/) Word.new name, origin, type, similar, description end |