Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor to use rspec, bundler, proper namespace
Also, remove decodable module
- Loading branch information
Showing
19 changed files
with
93 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.rvmrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--colour |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
source "http://rubygems.org" | ||
|
||
group :test do | ||
gem 'rspec', '~> 2.5.0' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
GEM | ||
remote: http://rubygems.org/ | ||
specs: | ||
diff-lcs (1.1.2) | ||
rspec (2.5.0) | ||
rspec-core (~> 2.5.0) | ||
rspec-expectations (~> 2.5.0) | ||
rspec-mocks (~> 2.5.0) | ||
rspec-core (2.5.1) | ||
rspec-expectations (2.5.0) | ||
diff-lcs (~> 1.1.2) | ||
rspec-mocks (2.5.0) | ||
|
||
PLATFORMS | ||
java | ||
ruby | ||
|
||
DEPENDENCIES | ||
rspec (~> 2.5.0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
require 'rspec/core/rake_task' | ||
|
||
desc "Run specs" | ||
RSpec::Core::RakeTask.new(:spec) | ||
|
||
task :default => :spec |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,9 @@ | ||
raise "ZXing requires JRuby" unless defined?(JRuby) | ||
|
||
require File.expand_path( File.dirname(__FILE__) + '/core.jar' ) # ZXing core classes | ||
require File.expand_path( File.dirname(__FILE__) + '/javase.jar' ) # ZXing JavaSE classes | ||
|
||
require 'uri' | ||
|
||
# Google ZXing classes | ||
java_import com.google.zxing.MultiFormatReader | ||
java_import com.google.zxing.BinaryBitmap | ||
java_import com.google.zxing.Binarizer | ||
java_import com.google.zxing.common.GlobalHistogramBinarizer | ||
java_import com.google.zxing.LuminanceSource | ||
java_import com.google.zxing.client.j2se.BufferedImageLuminanceSource | ||
|
||
# Standard Java classes | ||
java_import javax.imageio.ImageIO | ||
java_import java.net.URL | ||
require 'zxing/decoder' | ||
|
||
module ZXing | ||
|
||
@@decoder = MultiFormatReader.new | ||
|
||
# Transform the module into a singleton! | ||
extend self | ||
|
||
def decode(descriptor) | ||
begin | ||
decode!(descriptor) | ||
rescue NativeException | ||
return nil | ||
end | ||
end | ||
|
||
def decode!(descriptor) | ||
descriptor = descriptor.path if descriptor.respond_to? :path | ||
descriptor = descriptor.to_s | ||
descriptor = case descriptor | ||
when URI.regexp(['http', 'https']) | ||
URL.new(descriptor) | ||
else | ||
Java::JavaIO::File.new(descriptor) | ||
end | ||
image = ImageIO.read(descriptor) | ||
bitmap = to_bitmap(image) | ||
@@decoder.decode(bitmap).to_s | ||
end | ||
|
||
private | ||
|
||
def to_bitmap(image) | ||
luminance = BufferedImageLuminanceSource.new(image) | ||
binarizer = GlobalHistogramBinarizer.new(luminance) | ||
BinaryBitmap.new(binarizer) | ||
def decode(file) | ||
Decoder.new(file).decode | ||
end | ||
end |
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
module ZXing | ||
unless RUBY_PLATFORM != 'java' | ||
require 'java' | ||
require 'zxing/core.jar' | ||
require 'zxing/javase.jar' | ||
|
||
java_import com.google.zxing.MultiFormatReader | ||
java_import com.google.zxing.BinaryBitmap | ||
java_import com.google.zxing.Binarizer | ||
java_import com.google.zxing.common.GlobalHistogramBinarizer | ||
java_import com.google.zxing.LuminanceSource | ||
java_import com.google.zxing.client.j2se.BufferedImageLuminanceSource | ||
|
||
java_import javax.imageio.ImageIO | ||
|
||
class Decoder | ||
attr_accessor :file | ||
|
||
def initialize(file) | ||
self.file = file | ||
end | ||
|
||
def decode | ||
MultiFormatReader.new.decode(bitmap).to_s | ||
end | ||
|
||
def bitmap | ||
BinaryBitmap.new(binarizer) | ||
end | ||
|
||
def image | ||
ImageIO.read(Java::JavaIO::File.new(file)) | ||
end | ||
|
||
def luminance | ||
BufferedImageLuminanceSource.new(image) | ||
end | ||
|
||
def binarizer | ||
GlobalHistogramBinarizer.new(luminance) | ||
end | ||
end | ||
end | ||
end |
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
lib = File.expand_path('../lib', __FILE__) | ||
$:.unshift lib unless $:.include?(lib) | ||
|
||
require 'zxing' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require 'spec_helper' | ||
|
||
describe ZXing do | ||
describe ".decode" do | ||
let(:file) { File.expand_path('../fixtures/example.png', __FILE__) } | ||
it "decodes png files" do | ||
ZXing.decode(file).should == "example" | ||
end | ||
end | ||
end |
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.