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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e2b3ea52b01e7908042f2a56bc3c0808a585717d
4
- data.tar.gz: f6b64578a320970f6d7448e9802a026cc84cbcd0
3
+ metadata.gz: 8d70a6f8f513205be899a6c608857494b9f6f0f1
4
+ data.tar.gz: 64c7891d7be3db78dbb7b03af6e04149bc5766ff
5
5
  SHA512:
6
- metadata.gz: 7a0051b46b94523be5fb7afa74284d68c403f0c7abb5db8c6ad4ee32224ee503b459433e0f56fe49f7c09cd36c2b023267877a205ac7b9b0708609d1eb237f19
7
- data.tar.gz: 09de54dc1551e5e434f113b224909eff796152b107d688a77e1d6ac8c55ed35c81562152afcc926e208e703ba11f80a37ef81cb65337b90a4a316e30a53a5df4
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
- BingDictionary::Base.translate(ARGV.join ' ')
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?
@@ -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
@@ -1,3 +1,3 @@
1
1
  module BingDictionary
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
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.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-03-07 00:00:00.000000000 Z
11
+ date: 2016-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler