daumdic 0.0.1
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 +7 -0
- data/lib/daumdic.rb +64 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 831127f0269c31c8b47a579f259ea6637553cf73
|
4
|
+
data.tar.gz: 914d7a7bedc68a4fdfe4d53b04af8f1fb3273eb5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e54bd1423e619a5547a346d5b64bb531452f45e6ae2005845099401fe0744970781a1c80b3dfe1c2073d7993d340bb15c1d546294ff1d81403407d2143a4ca8a
|
7
|
+
data.tar.gz: dbac3bd92118bf5dfb8836a8fd981039138392f51a6941640b95c41cc35cf77d1204c13afcd44a6c767173d1368752caf078892652bee698f1e6e3ac4cf2f31a
|
data/lib/daumdic.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'open-uri'
|
4
|
+
|
5
|
+
class Daumdic
|
6
|
+
# 다음사전에 단어를 검색한 후, 한줄짜리 결과를 출력한다.
|
7
|
+
def self.search(input)
|
8
|
+
return if input.nil?
|
9
|
+
return if (input = input.strip).empty?
|
10
|
+
|
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
|
+
|
15
|
+
language = doc
|
16
|
+
.css('.search_fst .tit_searchfd')
|
17
|
+
.text.strip
|
18
|
+
if /^(.*)어 사전$/.match language
|
19
|
+
language = $1
|
20
|
+
end
|
21
|
+
|
22
|
+
word = doc
|
23
|
+
.css('.search_fst .clean_word .tit_word > a:first')
|
24
|
+
.text.strip
|
25
|
+
|
26
|
+
pronounce = doc
|
27
|
+
.css('.search_fst .clean_word span.pronounce_word')
|
28
|
+
.map { |n| n.text.strip }
|
29
|
+
.first
|
30
|
+
|
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(', ')
|
35
|
+
|
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
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: daumdic
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hyeon Kim
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-13 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Daum Dictionary API written in ruby.
|
14
|
+
email: simnalamburt@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/daumdic.rb
|
20
|
+
homepage: https://github.com/simnalamburt/daumdic-ruby
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.4.5.1
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Daum Dictionary
|
44
|
+
test_files: []
|