eric_tools 0.0.6 → 0.0.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f2184ed8d3f5ab055a6d14ee23c87a6c0fe2172c
4
- data.tar.gz: 8b78d07ed478d4c4e622566125a8791f9dc605d7
3
+ metadata.gz: aaa95e8c3d4abf793490a33ccc35cc3361b21254
4
+ data.tar.gz: ad3f71f95ff2d5da11dc78b7a7a8d98308320a27
5
5
  SHA512:
6
- metadata.gz: 84d2289e26c97aabae2ca244713ca4bd6d44214891ab0baf509b3e0b235e35657839c28107344bc788fb02135b9496541d731adf9308f356031f3f0a682a920d
7
- data.tar.gz: 93daf03c07f5ae87911e4547513e4d2b6f34480d8f31ac435288d7d19a8d56fe04af549f7c8f523abc210482bffd4a9297c81186f0cbd434e5bee399e5b2c740
6
+ metadata.gz: 1dc1defd2ce7a33c04570ef2d21215bedc615a6b641721def74bc922e71ae39385c8bbe542864a101c444d3684794fa73c126d9c07f962fdc8fd53f9e230e6e9
7
+ data.tar.gz: 06dcc58e2468ceb10ad913998bf7434dafe30da9386b84a9c54c45c097a30cb8eb52a61069dd1b4ebcdf24fa05c615834387b18c5e1437ad6a80590929072a19
Binary file
data/Gemfile CHANGED
@@ -5,4 +5,9 @@
5
5
  gemspec :name => 'eric_tools'
6
6
 
7
7
  gem 'nokogiri'
8
- gem 'rest-client'
8
+ gem 'rest-client'
9
+
10
+ # 生产条码,以及两个依赖gem
11
+ gem 'barby'
12
+ gem 'chunky_png'
13
+ gem 'rqrcode'
@@ -2,6 +2,9 @@ require 'nokogiri'
2
2
  require 'rest_client'
3
3
  require "eric_tools/version"
4
4
  require 'json'
5
+ require 'barby/barcode/code_128'
6
+ require 'barby/outputter/png_outputter'
7
+ require 'barby/barcode/qr_code'
5
8
 
6
9
  require File.dirname(__FILE__) + '/eric_tools/array.rb'
7
10
  require File.dirname(__FILE__) + '/eric_tools/business_exception.rb'
@@ -13,6 +16,7 @@ require File.dirname(__FILE__) + '/eric_tools/string.rb'
13
16
  require File.dirname(__FILE__) + '/eric_tools/symbol.rb'
14
17
  require File.dirname(__FILE__) + '/eric_tools/time.rb'
15
18
  require File.dirname(__FILE__) + '/eric_tools/version.rb'
19
+ require File.dirname(__FILE__) + '/eric_tools/barby_tools.rb'
16
20
 
17
21
  module EricTools
18
22
 
@@ -0,0 +1,34 @@
1
+ module BarbyTools
2
+
3
+ #生成的图片都比较小,官方的对png控制似乎无效
4
+ # ------会生成png文件, 一般每个大小不超过1kb, 但是文件需要自己去清除--------
5
+
6
+ # 生成条码, 不支持utf-8, 比如中文.
7
+ # 支持参数:
8
+ # content, 要转换的字符串
9
+ # file_path, 要保存的文件路径(png)
10
+ def self.create_barcode options
11
+ barcode = Barby::Code128B.new(options[:content])
12
+ blob = Barby::PngOutputter.new(barcode).to_png(:height => 20, :margin => 5)
13
+ unless File.exist? options[:file_path]
14
+ File.open(options[:file_path], 'wb'){|f|
15
+ f.write blob.force_encoding("ISO-8859-1") #在rails环境中,如果不encode,会报错
16
+ }
17
+ end
18
+ end
19
+
20
+ # 生成二维码. 支持中文
21
+ # 支持参数:
22
+ # content, 要转换的字符串
23
+ # file_path, 要保存的文件路径(png)
24
+ def self.create_qrcode options
25
+ qrcode = Barby::QrCode.new(options[:content])
26
+ blob = Barby::PngOutputter.new(qrcode).to_png(:height => 20, :margin => 5)
27
+ unless File.exist? options[:file_path]
28
+ File.open(options[:file_path], 'wb'){|f|
29
+ f.write blob.force_encoding("ISO-8859-1")
30
+ }
31
+ end
32
+ end
33
+
34
+ end
@@ -1,3 +1,3 @@
1
1
  module EricTools
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eric_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - 刘晓琦
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-20 00:00:00.000000000 Z
11
+ date: 2016-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -45,6 +45,7 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
+ - .DS_Store
48
49
  - .gitignore
49
50
  - .rvmrc
50
51
  - Gemfile
@@ -54,6 +55,7 @@ files:
54
55
  - eric_tools.gemspec
55
56
  - lib/eric_tools.rb
56
57
  - lib/eric_tools/array.rb
58
+ - lib/eric_tools/barby_tools.rb
57
59
  - lib/eric_tools/business_exception.rb
58
60
  - lib/eric_tools/date.rb
59
61
  - lib/eric_tools/date_time.rb