bing_dictionary 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/dict +11 -1
- data/lib/bing_dictionary.rb +11 -3
- data/lib/bing_dictionary/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d70a6f8f513205be899a6c608857494b9f6f0f1
|
4
|
+
data.tar.gz: 64c7891d7be3db78dbb7b03af6e04149bc5766ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c3f39b00a791203d4a73a2ea610a3de370a8722d47d24fb40cb2b6f73bf7b2d4d8e621fef6187aef8ba1a51778450dada0b0cb5cf0d2c25089e73ebc2b36657
|
7
|
+
data.tar.gz: 96be2ef7575babb693526e0671054734179512f7dc1322d7ca0237abc0925381b0383fffc2d94f765cfc4c994a58ae30e69079fc1a34c8a95bd8c283bc101220
|
data/bin/dict
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require "bing_dictionary"
|
4
|
+
require 'optparse'
|
4
5
|
|
5
|
-
|
6
|
+
options = {}
|
7
|
+
OptionParser.new do |opts|
|
8
|
+
opts.banner = "Usage: dict [-p] hello"
|
9
|
+
|
10
|
+
opts.on("-p", "--[no-]pronounce", "Pronounce the word") do |v|
|
11
|
+
options[:pronounce] = v
|
12
|
+
end
|
13
|
+
end.parse!
|
14
|
+
|
15
|
+
BingDictionary::Base.translate(ARGV.join(' '), options) unless ARGV.empty?
|
data/lib/bing_dictionary.rb
CHANGED
@@ -7,16 +7,17 @@ module BingDictionary
|
|
7
7
|
class Base
|
8
8
|
attr_reader :doc
|
9
9
|
|
10
|
-
def self.translate(word)
|
11
|
-
self.new(word).translate
|
10
|
+
def self.translate(word, options = {})
|
11
|
+
self.new(word, options).translate
|
12
12
|
rescue SocketError
|
13
13
|
warn 'Connection failed! Please check your network.'
|
14
14
|
exit 1
|
15
15
|
end
|
16
16
|
|
17
|
-
def initialize(word)
|
17
|
+
def initialize(word, options = {})
|
18
18
|
file = open("http://cn.bing.com/dict/?q=#{CGI::escape(word)}")
|
19
19
|
@doc = Nokogiri::HTML(file)
|
20
|
+
@options = options
|
20
21
|
end
|
21
22
|
|
22
23
|
def translate
|
@@ -24,6 +25,7 @@ module BingDictionary
|
|
24
25
|
machine if doc.at_css('.smt_hw')
|
25
26
|
sentence if doc.at_css('#sentenceSeg .se_li')
|
26
27
|
guess if doc.at_css('.dym_area')
|
28
|
+
pronounce if doc.at_css('#headword') && @options[:pronounce]
|
27
29
|
end
|
28
30
|
|
29
31
|
def head
|
@@ -35,6 +37,12 @@ module BingDictionary
|
|
35
37
|
end
|
36
38
|
end
|
37
39
|
|
40
|
+
def pronounce
|
41
|
+
url = doc.at_css('.hd_tf_lh .hd_tf a').attr('onclick').match(/http.*mp3/)
|
42
|
+
`curl -o /tmp/dict.mp3 #{url} &> /dev/null`
|
43
|
+
`afplay /tmp/dict.mp3`
|
44
|
+
end
|
45
|
+
|
38
46
|
def machine
|
39
47
|
puts doc.at_css('.smt_hw').text
|
40
48
|
puts doc.at_css('.p1-10').text
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bing_dictionary
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- lingceng
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-05-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|