daumdic 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/daumdic.rb +24 -45
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 831127f0269c31c8b47a579f259ea6637553cf73
4
- data.tar.gz: 914d7a7bedc68a4fdfe4d53b04af8f1fb3273eb5
3
+ metadata.gz: 53153ed2de88df68a78fbc0acba0cfd7e80e0fc8
4
+ data.tar.gz: 70aacc7f5f41a5038ffe175dad2f67787362ac7a
5
5
  SHA512:
6
- metadata.gz: e54bd1423e619a5547a346d5b64bb531452f45e6ae2005845099401fe0744970781a1c80b3dfe1c2073d7993d340bb15c1d546294ff1d81403407d2143a4ca8a
7
- data.tar.gz: dbac3bd92118bf5dfb8836a8fd981039138392f51a6941640b95c41cc35cf77d1204c13afcd44a6c767173d1368752caf078892652bee698f1e6e3ac4cf2f31a
6
+ metadata.gz: ea2376dba3731f528d7a8bf59852653b2239e8228df1825ecf93cfd9003c785025ee92efee5a58cec514519945f55c985d8e679a0645b783301bcda1dd06e8f2
7
+ data.tar.gz: 0c9858c64f748e69128557db94d07e5eb4277b82e9d3b208e114707f7acabee03453be5ec0670427727e86057e4591287d60e51cfbced8f047d1cebd69dd71b4
@@ -9,56 +9,35 @@ class Daumdic
9
9
  return if (input = input.strip).empty?
10
10
 
11
11
  doc = Nokogiri::HTML(open(URI.escape("http://dic.daum.net/search.do?q=#{input}")))
12
- if doc.css('.search_result1').any?
13
- # Exact match
14
12
 
15
- language = doc
16
- .css('.search_fst .tit_searchfd')
17
- .text.strip
18
- if /^(.*)어 사전$/.match language
19
- language = $1
20
- end
13
+ # Look for alternatives
14
+ rel = doc.css('.link_speller').map(&:text).join(', ')
15
+ return rel unless rel.empty?
21
16
 
22
- word = doc
23
- .css('.search_fst .clean_word .tit_word > a:first')
24
- .text.strip
17
+ # Got some results
18
+ box = doc.css('.search_box')[0]
19
+ return if box.nil?
25
20
 
26
- pronounce = doc
27
- .css('.search_fst .clean_word span.pronounce_word')
28
- .map { |n| n.text.strip }
29
- .first
21
+ word = box.css('.txt_cleansch').text
22
+ meaning = box.css('.txt_search').map(&:text).join(', ')
23
+ pronounce = box.css('.txt_pronounce').first&.text
24
+ lang = box.parent.css('.tit_word').text
25
+ if /^(.*)어사전$/.match(lang); lang = $1 end
30
26
 
31
- meaning = doc
32
- .css('.search_fst .clean_word ul.list_mean > li')
33
- .map { |n| n.xpath("node()[not(@class='num_g1')]").text.strip }
34
- .join(', ')
27
+ # Failed to parse daumdic
28
+ return if meaning.empty?
35
29
 
36
- # Failed to parse daumdic
37
- return if meaning.empty?
38
-
39
- # Make a result message
40
- result = ''
41
- unless ['한국', '영', '일본', '한자 사전'].include? language
42
- result += "(#{language}) "
43
- end
44
- unless pronounce.nil?
45
- result += "#{pronounce} "
46
- end
47
- if input != word
48
- result += "#{word} "
49
- end
50
- result += meaning
51
- elsif doc.css('.speller_search').any?
52
- # Not found, but there're some alternatives
53
- alternatives = doc
54
- .css('.speller_search > a')
55
- .map(&:text)
56
- .join(', ')
57
-
58
- alternatives
59
- else
60
- # No idea
61
- nil
30
+ # Make a result message
31
+ result = ''
32
+ unless ['한국', '영', '일본', '한자사전'].include? lang
33
+ result += "(#{lang}) "
34
+ end
35
+ if input != word
36
+ result += "#{word} "
37
+ end
38
+ unless pronounce.nil?
39
+ result += "#{pronounce} "
62
40
  end
41
+ result += meaning
63
42
  end
64
43
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: daumdic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hyeon Kim
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-13 00:00:00.000000000 Z
11
+ date: 2016-05-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Daum Dictionary API written in ruby.
14
14
  email: simnalamburt@gmail.com
@@ -37,7 +37,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
37
37
  version: '0'
38
38
  requirements: []
39
39
  rubyforge_project:
40
- rubygems_version: 2.4.5.1
40
+ rubygems_version: 2.5.1
41
41
  signing_key:
42
42
  specification_version: 4
43
43
  summary: Daum Dictionary