zbar 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
@@ -0,0 +1,15 @@
1
+ nguage: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ - 1.9.2
6
+ - jruby-18mode
7
+ - jruby-19mode
8
+ - rbx-18mode
9
+ - rbx-19mode
10
+ - ruby-head
11
+ - jruby-head
12
+ - 1.8.7
13
+ - ree
14
+ before_install:
15
+ - sudo apt-get install libzbar-dev
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :development do
4
+ gem "rspec", "~> 2.12.0"
5
+ gem "rspec", "~> 2.12.0"
6
+ gem "rdoc", "~> 3.12"
7
+ gem "bundler", "~> 1.0"
8
+ gem "jeweler", "~> 1.8.4"
9
+ end
10
+
11
+ gem "ffi", ">= 1.0.0"
@@ -1,7 +1,7 @@
1
1
  = zbar
2
2
  by Will Glynn
3
3
 
4
- http://github.com/delta407/ruby-zbar
4
+ http://github.com/willglynn/ruby-zbar
5
5
 
6
6
  == DESCRIPTION:
7
7
 
@@ -56,4 +56,4 @@ Doesn't expose all ZBar functionality, including:
56
56
 
57
57
  == Copyright
58
58
 
59
- Copyright (c) 2010 Will Glynn. See LICENSE for details.
59
+ Copyright (c) 2010-2013 Will Glynn. See LICENSE for details.
data/Rakefile CHANGED
@@ -1,48 +1,37 @@
1
- require 'rubygems'
2
- require 'rake'
1
+ # encoding: utf-8
3
2
 
3
+ require 'rubygems'
4
+ require 'bundler'
4
5
  begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "zbar"
8
- gem.summary = "Ruby bindings for ZBar, a barcode recognition library"
9
- gem.description ="Ruby bindings for ZBar, a barcode recognition library. Uses FFI to interact with the underlying C library, but has no other dependencies."
10
- gem.email = "will@willglynn.com"
11
- gem.homepage = "http://github.com/delta407/ruby-zbar"
12
- gem.authors = ["Will Glynn"]
13
- gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
- gem.add_dependency "ffi", ">= 0"
15
- end
16
- Jeweler::GemcutterTasks.new
17
- rescue LoadError
18
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
19
11
  end
12
+ require 'rake'
20
13
 
21
- require 'rake/testtask'
22
- Rake::TestTask.new(:test) do |test|
23
- test.libs << 'lib' << 'test'
24
- test.pattern = 'test/**/test_*.rb'
25
- test.verbose = true
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ gem.name = "zbar"
17
+ gem.summary = "Ruby bindings for ZBar, a barcode recognition library"
18
+ gem.description ="Ruby bindings for ZBar, a barcode recognition library. Uses FFI to interact with the underlying C library, but has no other dependencies."
19
+ gem.email = "will@willglynn.com"
20
+ gem.homepage = "http://github.com/delta407/ruby-zbar"
21
+ gem.authors = ["Will Glynn"]
22
+ # dependencies defined in Gemfile
26
23
  end
24
+ Jeweler::RubygemsDotOrgTasks.new
27
25
 
28
- begin
29
- require 'rcov/rcovtask'
30
- Rcov::RcovTask.new do |test|
31
- test.libs << 'test'
32
- test.pattern = 'test/**/test_*.rb'
33
- test.verbose = true
34
- end
35
- rescue LoadError
36
- task :rcov do
37
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
- end
26
+ require 'rspec/core'
27
+ require 'rspec/core/rake_task'
28
+ RSpec::Core::RakeTask.new(:spec) do |spec|
29
+ spec.pattern = FileList['spec/**/*_spec.rb']
39
30
  end
40
31
 
41
- task :test => :check_dependencies
42
-
43
- task :default => :test
32
+ task :default => :spec
44
33
 
45
- require 'rake/rdoctask'
34
+ require 'rdoc/task'
46
35
  Rake::RDocTask.new do |rdoc|
47
36
  version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
37
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.0
@@ -4,3 +4,4 @@ require 'zbar/lib'
4
4
  require 'zbar/symbol'
5
5
  require 'zbar/processor'
6
6
  require 'zbar/image'
7
+ require 'zbar/jpeg'
@@ -17,6 +17,9 @@ module ZBar
17
17
  # and convert it into a greyscale image suitable for further processing.
18
18
  # This conversion may fail if ZBar was not built with <tt>--with-jpeg</tt>.
19
19
  def self.from_jpeg(io_or_string)
20
+ raise "JPEG support is not available in your copy of libzbar" unless ZBar::JPEG.available?
21
+ ZBar::JPEG.warn_once_if_bugged
22
+
20
23
  if io_or_string.respond_to?(:read)
21
24
  io_or_string = io_or_string.read
22
25
  end
@@ -37,10 +40,17 @@ module ZBar
37
40
  # http://netpbm.sourceforge.net/doc/pgm.html.
38
41
  def self.from_pgm(io_or_string)
39
42
  if io_or_string.respond_to?(:read)
40
- io_or_string = io_or_string.read
43
+ string = io_or_string.read
44
+ else
45
+ string = io_or_string
41
46
  end
42
47
 
43
- image_data = io_or_string.gsub(/^(P5)\s([0-9]+)\s([0-9]+)\s([0-9]+)\s/, '')
48
+ # Ensure we're in binary mode
49
+ if string.respond_to? :force_encoding
50
+ string.force_encoding 'binary'
51
+ end
52
+
53
+ image_data = string.gsub(/^(P5)\s([0-9]+)\s([0-9]+)\s([0-9]+)\s/, '')
44
54
  if $1 != 'P5'
45
55
  raise ArgumentError, "input must be a PGM file"
46
56
  end
@@ -90,13 +100,30 @@ module ZBar
90
100
  end
91
101
 
92
102
  # Attempt to recognize barcodes in this image, using the supplied processor
93
- # (if any), falling back to defaults.
103
+ # or processor configuration (if any), falling back to defaults.
94
104
  #
95
105
  # Returns an array of ZBar::Symbol objects.
96
- def process(processor = nil)
97
- processor ||= Processor.new
106
+ def process(processor_or_config = nil)
107
+ if processor_or_config.respond_to?(:process)
108
+ processor = processor_or_config
109
+ elsif processor_or_config.nil?
110
+ processor = Processor.new
111
+ else
112
+ processor = Processor.new(processor_or_config)
113
+ end
114
+
98
115
  processor.process(self)
99
116
  end
117
+
118
+ # Retrieve the image's width in pixels
119
+ def width
120
+ ZBar.zbar_image_get_width(@img)
121
+ end
122
+
123
+ # Retrieve the image's height in pixels
124
+ def height
125
+ ZBar.zbar_image_get_height(@img)
126
+ end
100
127
  end
101
128
 
102
129
  end
@@ -0,0 +1,57 @@
1
+ # zbar-0.10 has a problem handling certain JPEGs:
2
+ # * http://sourceforge.net/p/zbar/discussion/664596/thread/58b8d79b
3
+ # * https://github.com/willglynn/ruby-zbar/issues/2
4
+ #
5
+ # This is a problem in the underlying C library. It is fixed in zbar's source
6
+ # control repository, but an updated package has not yet been released.
7
+ #
8
+ # If this affects you, ask whoever compiled your libzbar to apply this patch:
9
+ # https://gist.github.com/willglynn/5659946
10
+
11
+ module ZBar::JPEG
12
+ # Is JPEG support available?
13
+ def self.available?
14
+ if @available.nil?
15
+ @available = image_works?(WorkingBits)
16
+ end
17
+
18
+ @available
19
+ end
20
+
21
+ # Is JPEG support bugged?
22
+ # See https://github.com/willglynn/ruby-zbar/issues/2 for details.
23
+ def self.bugged?
24
+ if @bugged.nil?
25
+ @bugged = available? && !image_works?(BuggedBits)
26
+ end
27
+
28
+ @bugged
29
+ end
30
+
31
+ def self.warn_once_if_bugged #:nodoc:
32
+ @warn_attempted ||= begin
33
+ if bugged?
34
+ STDERR.print "Your libzbar has a JPEG bug. Some images will fail to process correctly.\nSee: https://github.com/willglynn/ruby-zbar/blob/master/lib/zbar/jpeg.rb\n"
35
+ end
36
+ true
37
+ end
38
+ end
39
+
40
+ protected
41
+ WorkingBits = "\377\330\377\340\000\020JFIF\000\001\001\000\000\001\000\001\000\000\377\333\000C\000\e\032\032)\035)A&&AB///BG?>>?GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG\377\333\000C\001\035))4&4?((?G?5?GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG\377\300\000\021\b\000\b\000\b\003\001\"\000\002\021\001\003\021\001\377\304\000\025\000\001\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\006\377\304\000\024\020\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\377\304\000\024\001\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\377\304\000\024\021\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\377\332\000\f\003\001\000\002\021\003\021\000?\000\246\000\037\377\331"
42
+ BuggedBits = "\377\330\377\340\000\020JFIF\000\001\002\000\000d\000d\000\000\377\354\000\021Ducky\000\001\000\004\000\000\000\000\000\000\377\356\000\016Adobe\000d\300\000\000\000\001\377\333\000\204\000\e\032\032)\035)A&&AB///BG?>>?GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG\001\035))4&4?((?G?5?GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG\377\300\000\021\b\000\b\000\b\003\001\"\000\002\021\001\003\021\001\377\304\000K\000\001\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\006\001\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\020\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\021\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\377\332\000\f\003\001\000\002\021\003\021\000?\000\246\000\037\377\331"
43
+
44
+ def self.image_works?(bits) #:nodoc:
45
+ ZBar::Image.new.tap { |img|
46
+ img.set_data(ZBar::Format::JPEG, bits)
47
+ img.convert(ZBar::Format::Y800)
48
+ } && true
49
+ rescue ArgumentError
50
+ if $!.to_s == "conversion failed"
51
+ false
52
+ else
53
+ raise
54
+ end
55
+ end
56
+
57
+ end
@@ -9,9 +9,11 @@ module ZBar
9
9
  begin
10
10
  ffi_lib(*paths)
11
11
  rescue LoadError => le
12
- raise LoadError,
13
- "didn't find libzbar on your system. " +
14
- "Please install zbar (http://zbar.sourceforge.net/)"
12
+ raise LoadError, [
13
+ "Didn't find libzbar on your system",
14
+ "Please install zbar (http://zbar.sourceforge.net/) or ZBAR_LIB if it's in a weird place",
15
+ "FFI::Library::ffi_lib() failed with error: #{le}"
16
+ ].join("\n")
15
17
  end
16
18
 
17
19
  attach_function :zbar_symbol_get_type, [:pointer], :int
@@ -28,15 +30,20 @@ module ZBar
28
30
  attach_function :zbar_image_first_symbol, [:pointer], :pointer
29
31
  attach_function :zbar_image_set_format, [:pointer, :ulong], :void
30
32
  attach_function :zbar_image_convert, [:pointer, :ulong], :pointer
33
+ attach_function :zbar_image_get_width, [:pointer], :int
34
+ attach_function :zbar_image_get_height, [:pointer], :int
31
35
  attach_function :zbar_image_set_size, [:pointer, :uint, :uint], :void
32
36
  attach_function :zbar_image_set_data, [:pointer, :buffer_in, :uint, :pointer], :void
33
37
 
34
38
  attach_function :zbar_processor_create, [:int], :pointer
35
39
  attach_function :zbar_processor_destroy, [:pointer], :void
36
40
  attach_function :zbar_processor_init, [:pointer, :string, :int], :int
41
+ attach_function :zbar_processor_set_config, [:pointer, :int, :int, :int], :int
37
42
 
38
43
  attach_function :zbar_process_image, [:pointer, :pointer], :int
39
44
 
45
+ attach_function :zbar_parse_config, [:string, :pointer, :pointer, :pointer], :int
46
+
40
47
  attach_function :zbar_set_verbosity, [:int], :void
41
48
  attach_function :zbar_get_symbol_name, [:int], :string
42
49
  attach_function :zbar_get_addon_name, [:int], :string
@@ -1,9 +1,17 @@
1
1
  module ZBar
2
2
  class Processor
3
3
  # Create a new processor.
4
- def initialize(threads = 0)
4
+ # Accepts a hash of configurations
5
+ def initialize(config = nil)
6
+ # This function used to accept an integer refering to the number of threads
7
+ if config.kind_of?(Fixnum)
8
+ config = { :threads => config }
9
+ end
10
+
11
+ config ||= {}
12
+
5
13
  @processor = FFI::AutoPointer.new(
6
- ZBar.zbar_processor_create(threads),
14
+ ZBar.zbar_processor_create(config[:threads] || 0),
7
15
  ZBar.method(:zbar_processor_destroy)
8
16
  )
9
17
 
@@ -11,8 +19,76 @@ module ZBar
11
19
  ZBar._zbar_error_spew(@processor, 0)
12
20
  raise "error!"
13
21
  end
22
+
23
+ config.each { |key,value|
24
+ if key == :threads
25
+ # do nothing; we handled this above
26
+ else
27
+ setter = "#{key}=".to_sym
28
+ if respond_to?(setter)
29
+ send(setter, value)
30
+ else
31
+ raise ArgumentError, "unsupported configuration option: #{key}"
32
+ end
33
+ end
34
+ }
35
+ end
36
+
37
+ # Indicates that this processor should only search for the indicated symbologies.
38
+ # Accepts an array of the following symbologies, specified as a string or symbol:
39
+ # - qrcode
40
+ # - upca
41
+ # - upce
42
+ # - ean13
43
+ # - ean8
44
+ # - i25
45
+ # - scanner
46
+ # - isbn13
47
+ # - isbn10
48
+ # - code39
49
+ # - pdf417
50
+ # - code128
51
+ def symbologies=(symbologies)
52
+ self.zbar_config = ["disable"] + symbologies.map { |sym| "#{sym}.enable" }
53
+ true
54
+ end
55
+
56
+ # Indicates that this processor should only search for the indicated symbology.
57
+ # See #symbologies= for details.
58
+ def symbology=(symbology)
59
+ self.symbologies = [symbology]
60
+ end
61
+
62
+ # Configures this processor using the specified configuration string. See
63
+ # zbar_parse_config (zbar/config.c) for supported values.
64
+ def zbar_config=(config_value)
65
+ case config_value
66
+ when String
67
+ symbology = FFI::MemoryPointer.new :int
68
+ config_t = FFI::MemoryPointer.new :int
69
+ value = FFI::MemoryPointer.new :int
70
+
71
+ if ZBar.zbar_parse_config(config_value, symbology, config_t, value) == 0
72
+ # parsed successfully
73
+ if ZBar.zbar_processor_set_config(@processor, symbology.read_int, config_t.read_int, value.read_int) == 0
74
+ true
75
+ else
76
+ raise ArgumentError, "config string #{config_value.inspect} parsed but could not be set"
77
+ end
78
+ else
79
+ raise ArgumentError, "config string #{config_value.inspect} was not recognized"
80
+ end
81
+
82
+ when Enumerable
83
+ config_value.each { |value|
84
+ self.zbar_config = value
85
+ }
86
+
87
+ else
88
+ raise ArgumentError, "unsupported config value"
89
+ end
14
90
  end
15
-
91
+
16
92
  # Attempt to recognize barcodes in this image. Raises an exception if ZBar
17
93
  # signals an error, otherwise returns an array of ZBar::Symbol objects.
18
94
  def process(image)
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'zbar'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+ config.include FileHelpers
12
+ end
@@ -0,0 +1,13 @@
1
+ module FileHelpers
2
+ def file_path(filename)
3
+ File.dirname(__FILE__) + "/" + filename
4
+ end
5
+
6
+ def open_file(filename, &block)
7
+ File.open(file_path(filename), 'rb', &block)
8
+ end
9
+
10
+ def read_file(filename)
11
+ open_file(filename, &:read)
12
+ end
13
+ end
File without changes
File without changes
@@ -0,0 +1,60 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe ZBar::Image do
4
+
5
+ if !ZBar::JPEG.available?
6
+ pending "JPEG support is not available in your copy of libzbar; skipping tests"
7
+ elsif ZBar::JPEG.bugged?
8
+ ZBar::JPEG.warn_once_if_bugged
9
+ pending "JPEG support is broken in your copy of libzbar; skipping tests"
10
+ else
11
+ describe ".from_jpeg" do
12
+ let(:jpeg_data) { read_file jpeg_file }
13
+ subject { described_class.from_jpeg(jpeg_data) }
14
+ context "given test.jpg" do
15
+ let(:jpeg_file) { "test.jpg" }
16
+
17
+ its(:width) { should == 480 }
18
+ its(:height) { should == 240 }
19
+
20
+ describe "process" do
21
+ it "delegates to the passed processor" do
22
+ processor = double("processor")
23
+ expected_result = Object.new
24
+ processor.should_receive(:process).with(subject).and_return(expected_result)
25
+
26
+ subject.process(processor).should == expected_result
27
+ end
28
+
29
+ it "instantiates a new processor with no arguments" do
30
+ processor = double("processor")
31
+ processor.should_receive(:process)
32
+ ZBar::Processor.should_receive(:new).with().and_return(processor)
33
+ subject.process
34
+ end
35
+
36
+ it "instantiates a new processor with configuration" do
37
+ config_hash = { :foo => :bar }
38
+ processor = double("processor")
39
+ processor.should_receive(:process)
40
+ ZBar::Processor.should_receive(:new).with(config_hash).and_return(processor)
41
+ subject.process(config_hash)
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ describe ".from_pgm" do
49
+ let(:pgm_data) { read_file pgm_file }
50
+ let(:image) { described_class.from_pgm(pgm_data) }
51
+ subject { image }
52
+
53
+ context "given test.pgm" do
54
+ let(:pgm_file) { "test.pgm" }
55
+
56
+ its(:width) { should == 480 }
57
+ its(:height) { should == 240 }
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,113 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe ZBar::Processor do
4
+ describe "new" do
5
+ it "calls ZBar.zbar_processor_create" do
6
+ ZBar.should_receive(:zbar_processor_create).and_call_original
7
+ described_class.new
8
+ end
9
+
10
+ it "calls ZBar.zbar_processor_init" do
11
+ ZBar.should_receive(:zbar_processor_init).and_call_original
12
+ described_class.new
13
+ end
14
+
15
+ it "should instantiate with no parameters" do
16
+ described_class.new
17
+ end
18
+
19
+ it "should instantiate with an integer parameter" do
20
+ described_class.new(0)
21
+ end
22
+
23
+ it "should instantiate with an hash parameter" do
24
+ described_class.new(:threads => 0)
25
+ end
26
+ end
27
+
28
+ describe "#zbar_config=" do
29
+ it "calls ZBar.zbar_parse_config" do
30
+ ZBar.should_receive(:zbar_parse_config).with("disable", anything(), anything(), anything()).and_call_original
31
+ subject.zbar_config = "disable"
32
+ end
33
+
34
+ it "calls ZBar.zbar_processor_set_config" do
35
+ ZBar.should_receive(:zbar_processor_set_config).and_call_original
36
+ subject.zbar_config = "disable"
37
+ end
38
+
39
+ it "calls itself repeatedly when given an array" do
40
+ args = ["foo", :bar, 1]
41
+ subject.should_receive(:zbar_config=).with(args).and_call_original
42
+ args.each { |arg|
43
+ subject.should_receive(:zbar_config=).with(arg)
44
+ }
45
+ subject.zbar_config = args
46
+ end
47
+
48
+ it "succeeds for \"disable\"" do
49
+ subject.zbar_config = "disable"
50
+ end
51
+ it "succeeds for \"enable=0\"" do
52
+ subject.zbar_config = "enable=0"
53
+ end
54
+ it "succeeds for \"qrcode.enable=1\"" do
55
+ subject.zbar_config = "qrcode.enable=1"
56
+ end
57
+
58
+ it "raises ArgumentError for \"foo bar baz\"" do
59
+ lambda {
60
+ subject.zbar_config = "foo bar baz"
61
+ }.should raise_error ArgumentError
62
+ end
63
+ end
64
+
65
+ describe "#symbology=" do
66
+ it "delegates to #symbologies=" do
67
+ subject.should_receive(:symbologies=).with(['foo'])
68
+ subject.symbology = 'foo'
69
+ end
70
+ end
71
+
72
+ describe "#symbologies=" do
73
+ it "enables the selected symbologies" do
74
+ subject.should_receive(:zbar_config=).with(["disable", "foo.enable", "bar.enable"])
75
+ subject.symbologies = ['foo', :bar]
76
+ end
77
+ end
78
+
79
+ describe "#process" do
80
+ context "when processing test.pgm" do
81
+ let(:pgm_data) { read_file "test.pgm" }
82
+ let(:image) { ZBar::Image.from_pgm(pgm_data) }
83
+ let(:config) { {} }
84
+ let(:processor) { described_class.new(config) }
85
+ subject { processor.process(image) }
86
+
87
+ it "finds the expected symbol" do
88
+ symbols = subject
89
+ symbols.size.should == 1
90
+
91
+ symbol = symbols[0]
92
+ symbol.should be_kind_of ZBar::Symbol
93
+ symbol.data.should == "9876543210128"
94
+ symbol.symbology.should == "EAN-13"
95
+ end
96
+
97
+ context "when all symbologies are disabled" do
98
+ let(:config) { { :symbologies => [] } }
99
+ it { should be_empty }
100
+ end
101
+
102
+ context "when only a wrong symbology is enabled" do
103
+ let(:config) { { :symbology => :qrcode } }
104
+ it { should be_empty }
105
+ end
106
+
107
+ context "when the correct symbology is enabled" do
108
+ let(:config) { { :symbologies => ["qrcode", :ean13] } }
109
+ it { should_not be_empty }
110
+ end
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,5 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe ZBar do
4
+ it { should be_kind_of Module }
5
+ end
@@ -1,63 +1,75 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{zbar}
8
- s.version = "0.1.1"
7
+ s.name = "zbar"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Will Glynn"]
12
- s.date = %q{2010-08-29}
13
- s.description = %q{Ruby bindings for ZBar, a barcode recognition library. Uses FFI to interact with the underlying C library, but has no other dependencies.}
14
- s.email = %q{will@willglynn.com}
12
+ s.date = "2013-06-13"
13
+ s.description = "Ruby bindings for ZBar, a barcode recognition library. Uses FFI to interact with the underlying C library, but has no other dependencies."
14
+ s.email = "will@willglynn.com"
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README.rdoc"
17
+ "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
- ".gitignore",
22
- "LICENSE",
23
- "README.rdoc",
24
- "Rakefile",
25
- "VERSION",
26
- "lib/zbar.rb",
27
- "lib/zbar/image.rb",
28
- "lib/zbar/lib.rb",
29
- "lib/zbar/processor.rb",
30
- "lib/zbar/symbol.rb",
31
- "test/helper.rb",
32
- "test/test.jpg",
33
- "test/test.pgm",
34
- "test/test_zbar.rb",
35
- "zbar.gemspec"
21
+ ".rspec",
22
+ ".travis.yml",
23
+ "Gemfile",
24
+ "LICENSE",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "lib/zbar.rb",
29
+ "lib/zbar/image.rb",
30
+ "lib/zbar/jpeg.rb",
31
+ "lib/zbar/lib.rb",
32
+ "lib/zbar/processor.rb",
33
+ "lib/zbar/symbol.rb",
34
+ "spec/spec_helper.rb",
35
+ "spec/support/file_helpers.rb",
36
+ "spec/support/test.jpg",
37
+ "spec/support/test.pgm",
38
+ "spec/zbar/image_spec.rb",
39
+ "spec/zbar/processor_spec.rb",
40
+ "spec/zbar_spec.rb",
41
+ "zbar.gemspec"
36
42
  ]
37
- s.homepage = %q{http://github.com/delta407/ruby-zbar}
38
- s.rdoc_options = ["--charset=UTF-8"]
43
+ s.homepage = "http://github.com/delta407/ruby-zbar"
39
44
  s.require_paths = ["lib"]
40
- s.rubygems_version = %q{1.3.6}
41
- s.summary = %q{Ruby bindings for ZBar, a barcode recognition library}
42
- s.test_files = [
43
- "test/helper.rb",
44
- "test/test_zbar.rb"
45
- ]
45
+ s.rubygems_version = "1.8.25"
46
+ s.summary = "Ruby bindings for ZBar, a barcode recognition library"
46
47
 
47
48
  if s.respond_to? :specification_version then
48
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
49
49
  s.specification_version = 3
50
50
 
51
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
52
- s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
53
- s.add_runtime_dependency(%q<ffi>, [">= 0"])
51
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
52
+ s.add_runtime_dependency(%q<ffi>, [">= 1.0.0"])
53
+ s.add_development_dependency(%q<rspec>, ["~> 2.12.0"])
54
+ s.add_development_dependency(%q<rspec>, ["~> 2.12.0"])
55
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
56
+ s.add_development_dependency(%q<bundler>, ["~> 1.0"])
57
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
54
58
  else
55
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
56
- s.add_dependency(%q<ffi>, [">= 0"])
59
+ s.add_dependency(%q<ffi>, [">= 1.0.0"])
60
+ s.add_dependency(%q<rspec>, ["~> 2.12.0"])
61
+ s.add_dependency(%q<rspec>, ["~> 2.12.0"])
62
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
63
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
64
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
57
65
  end
58
66
  else
59
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
60
- s.add_dependency(%q<ffi>, [">= 0"])
67
+ s.add_dependency(%q<ffi>, [">= 1.0.0"])
68
+ s.add_dependency(%q<rspec>, ["~> 2.12.0"])
69
+ s.add_dependency(%q<rspec>, ["~> 2.12.0"])
70
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
71
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
72
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
61
73
  end
62
74
  end
63
75
 
metadata CHANGED
@@ -1,102 +1,168 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: zbar
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 1
8
- - 1
9
- version: 0.1.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Will Glynn
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2010-08-29 00:00:00 -05:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- name: thoughtbot-shoulda
12
+ date: 2013-06-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: ffi
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.0.0
22
+ type: :runtime
22
23
  prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- segments:
28
- - 0
29
- version: "0"
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.0.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 2.12.0
30
38
  type: :development
31
- version_requirements: *id001
32
- - !ruby/object:Gem::Dependency
33
- name: ffi
34
39
  prerelease: false
35
- requirement: &id002 !ruby/object:Gem::Requirement
36
- requirements:
37
- - - ">="
38
- - !ruby/object:Gem::Version
39
- segments:
40
- - 0
41
- version: "0"
42
- type: :runtime
43
- version_requirements: *id002
44
- description: Ruby bindings for ZBar, a barcode recognition library. Uses FFI to interact with the underlying C library, but has no other dependencies.
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 2.12.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 2.12.0
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.12.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: rdoc
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '3.12'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '3.12'
78
+ - !ruby/object:Gem::Dependency
79
+ name: bundler
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: '1.0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: '1.0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: jeweler
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 1.8.4
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 1.8.4
110
+ description: Ruby bindings for ZBar, a barcode recognition library. Uses FFI to interact
111
+ with the underlying C library, but has no other dependencies.
45
112
  email: will@willglynn.com
46
113
  executables: []
47
-
48
114
  extensions: []
49
-
50
- extra_rdoc_files:
115
+ extra_rdoc_files:
51
116
  - LICENSE
52
117
  - README.rdoc
53
- files:
118
+ files:
54
119
  - .document
55
- - .gitignore
120
+ - .rspec
121
+ - .travis.yml
122
+ - Gemfile
56
123
  - LICENSE
57
124
  - README.rdoc
58
125
  - Rakefile
59
126
  - VERSION
60
127
  - lib/zbar.rb
61
128
  - lib/zbar/image.rb
129
+ - lib/zbar/jpeg.rb
62
130
  - lib/zbar/lib.rb
63
131
  - lib/zbar/processor.rb
64
132
  - lib/zbar/symbol.rb
65
- - test/helper.rb
66
- - test/test.jpg
67
- - test/test.pgm
68
- - test/test_zbar.rb
133
+ - spec/spec_helper.rb
134
+ - spec/support/file_helpers.rb
135
+ - spec/support/test.jpg
136
+ - spec/support/test.pgm
137
+ - spec/zbar/image_spec.rb
138
+ - spec/zbar/processor_spec.rb
139
+ - spec/zbar_spec.rb
69
140
  - zbar.gemspec
70
- has_rdoc: true
71
141
  homepage: http://github.com/delta407/ruby-zbar
72
142
  licenses: []
73
-
74
143
  post_install_message:
75
- rdoc_options:
76
- - --charset=UTF-8
77
- require_paths:
144
+ rdoc_options: []
145
+ require_paths:
78
146
  - lib
79
- required_ruby_version: !ruby/object:Gem::Requirement
80
- requirements:
81
- - - ">="
82
- - !ruby/object:Gem::Version
83
- segments:
84
- - 0
85
- version: "0"
86
- required_rubygems_version: !ruby/object:Gem::Requirement
87
- requirements:
88
- - - ">="
89
- - !ruby/object:Gem::Version
90
- segments:
147
+ required_ruby_version: !ruby/object:Gem::Requirement
148
+ none: false
149
+ requirements:
150
+ - - ! '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ segments:
91
154
  - 0
92
- version: "0"
155
+ hash: 4088186622936310540
156
+ required_rubygems_version: !ruby/object:Gem::Requirement
157
+ none: false
158
+ requirements:
159
+ - - ! '>='
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
93
162
  requirements: []
94
-
95
163
  rubyforge_project:
96
- rubygems_version: 1.3.6
164
+ rubygems_version: 1.8.25
97
165
  signing_key:
98
166
  specification_version: 3
99
167
  summary: Ruby bindings for ZBar, a barcode recognition library
100
- test_files:
101
- - test/helper.rb
102
- - test/test_zbar.rb
168
+ test_files: []
data/.gitignore DELETED
@@ -1,21 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC
@@ -1,10 +0,0 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
- require 'shoulda'
4
-
5
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
- $LOAD_PATH.unshift(File.dirname(__FILE__))
7
- require 'zbar'
8
-
9
- class Test::Unit::TestCase
10
- end
@@ -1,42 +0,0 @@
1
- require 'helper'
2
-
3
- Path = File.dirname(__FILE__)
4
-
5
- class TestZBar < Test::Unit::TestCase
6
- should "read the right barcode from a PGM blob" do
7
- result = ZBar::Image.from_pgm(File.read("#{Path}/test.pgm")).process
8
- assert_equal(result.size, 1)
9
- assert_equal(result[0].data, '9876543210128')
10
- assert_equal(result[0].symbology, 'EAN-13')
11
- end
12
-
13
- should "read a barcode from a PGM file" do
14
- File.open("#{Path}/test.pgm") { |f|
15
- result = ZBar::Image.from_pgm(f).process
16
- assert_equal(result.size, 1)
17
- }
18
- end
19
-
20
- should "be able to re-use a processor" do
21
- processor = ZBar::Processor.new
22
- pgm = File.read("#{Path}/test.pgm")
23
-
24
- result1 = processor.process ZBar::Image.from_pgm(pgm)
25
- result2 = processor.process ZBar::Image.from_pgm(pgm)
26
- assert_equal(result1.size, 1)
27
- assert_equal(result2.size, 1)
28
- assert_equal(result1, result2)
29
- end
30
-
31
- should "read a barcode from a JPEG blob" do
32
- result = ZBar::Image.from_jpeg(File.read("#{Path}/test.jpg")).process
33
- assert_equal(result.size, 1)
34
- end
35
-
36
- should "read a barcode from a JPEG file" do
37
- File.open("#{Path}/test.jpg") { |f|
38
- result = ZBar::Image.from_jpeg(f).process
39
- assert_equal(result.size, 1)
40
- }
41
- end
42
- end