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.
- checksums.yaml +4 -4
- data/lib/daumdic.rb +24 -45
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53153ed2de88df68a78fbc0acba0cfd7e80e0fc8
|
4
|
+
data.tar.gz: 70aacc7f5f41a5038ffe175dad2f67787362ac7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea2376dba3731f528d7a8bf59852653b2239e8228df1825ecf93cfd9003c785025ee92efee5a58cec514519945f55c985d8e679a0645b783301bcda1dd06e8f2
|
7
|
+
data.tar.gz: 0c9858c64f748e69128557db94d07e5eb4277b82e9d3b208e114707f7acabee03453be5ec0670427727e86057e4591287d60e51cfbced8f047d1cebd69dd71b4
|
data/lib/daumdic.rb
CHANGED
@@ -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
|
-
|
16
|
-
|
17
|
-
|
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
|
-
|
23
|
-
|
24
|
-
|
17
|
+
# Got some results
|
18
|
+
box = doc.css('.search_box')[0]
|
19
|
+
return if box.nil?
|
25
20
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
-
|
32
|
-
|
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
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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
|
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-
|
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.
|
40
|
+
rubygems_version: 2.5.1
|
41
41
|
signing_key:
|
42
42
|
specification_version: 4
|
43
43
|
summary: Daum Dictionary
|