iciba 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/bin/fy CHANGED
@@ -25,7 +25,6 @@ OptionParser.new do |opts|
25
25
  end
26
26
  end
27
27
 
28
-
29
28
  def wrap_text(txt, col = 80)
30
29
  txt.gsub(/(.{1,#{col}})( +|$\n?)|(.{1,#{col}})/,
31
30
  "\\1\\3\n")
@@ -33,6 +32,9 @@ end
33
32
 
34
33
  if ARGV.empty?
35
34
  abort "Enter some words to lookup!"
35
+ elsif ARGV.first == 'open'
36
+ `open http://fy.iciba.com`
37
+ abort "opening http://fy.iciba.com"
36
38
  end
37
39
 
38
40
  regex = /https?:\/\/[\S]+/
@@ -41,7 +43,7 @@ links = ARGV.first.scan(regex)
41
43
  def loop_through_links(links)
42
44
  puts links.inspect
43
45
  links.each do |l|
44
- text = Readability::Document.new(Iciba::Tools.download(l).force_encoding("UTF-8")).content.gsub('<p>', '').gsub('</p>', "\r\n").gsub('</div></div>', '').gsub('<div><div>', '')
46
+ text = Readability::Document.new(Iciba::Tools.download(l).force_encoding("UTF-8")).content.gsub('<p>', '').gsub('</p>', "\r\n").gsub('</div>', '').gsub('<div>', '')
45
47
  puts wrap_text(text) unless text == ''
46
48
  puts '------------------------------------------------------------------------------------' unless text == ''
47
49
  end
@@ -2,3 +2,8 @@
2
2
  require "iciba/version"
3
3
  require 'iciba/tools'
4
4
  require 'iciba/fanyi'
5
+ class String
6
+ def contains_cjk?
7
+ !!(self =~ /\p{Han}|\p{Katakana}|\p{Hiragana}|\p{Hangul}/)
8
+ end
9
+ end
@@ -8,7 +8,8 @@ module Iciba
8
8
  def initialize(words, dir='auto', bin=false, extended=false)
9
9
  puts '------------------------------------------------------------------------------------' if bin
10
10
  # puts if bingit
11
- puts wrap_text(words, 40)
11
+ puts wrap_text(words, 40) if check_char(words) if bin
12
+ puts wrap_text(words) unless check_char(words) if bin
12
13
  puts '------------------------------------------------------------------------------------' if bin
13
14
  download_and_parse(words, dir, extended)
14
15
  puts wrap_text(self.result) if bin
@@ -20,6 +21,10 @@ module Iciba
20
21
  txt.gsub(/(.{1,#{col}})( +|$\n?)|(.{1,#{col}})/,
21
22
  "\\1\\3\n")
22
23
  end
24
+
25
+ def check_char(str)
26
+ str.contains_cjk?
27
+ end
23
28
 
24
29
 
25
30
  def download_and_parse(words, dir, extended)
@@ -1,3 +1,3 @@
1
1
  module Iciba
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iciba
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: