has_barcode 0.1.0

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.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Dan Pickett
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,33 @@
1
+ = has_barcode
2
+
3
+ A nice wrapper for Barcode generation using barby
4
+
5
+ class SomethingImportant
6
+ has_barcode :barcode,
7
+ :outputter => :png,
8
+ :type => :code_39,
9
+ :value => Proc.new{|p| p.number}
10
+
11
+ def number
12
+ self.id
13
+ end
14
+ end
15
+
16
+ SomethingImportant.new.barcode => Barby::Code39 object
17
+ SomethingImportant.new.barcode_data => <Barby::Code39 object>.to_png
18
+
19
+
20
+ == Note on Patches/Pull Requests
21
+
22
+ * Fork the project.
23
+ * Make your feature addition or bug fix.
24
+ * Add tests for it. This is important so I don't break it in a
25
+ future version unintentionally.
26
+ * Commit, do not mess with rakefile, version, or history.
27
+ (if you want to have your own version, that is fine but
28
+ bump version in a commit by itself I can ignore when I pull)
29
+ * Send me a pull request. Bonus points for topic branches.
30
+
31
+ == Copyright
32
+
33
+ Copyright (c) 2009 Dan Pickett. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,47 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "has_barcode"
8
+ gem.summary = %Q{Nice class method wrapper for Barby}
9
+ gem.description = %Q{Nice class method wrapper for Barby}
10
+ gem.email = "dpickett@enlightsolutions.com"
11
+ gem.homepage = "http://github.com/dpickett/has_barcode"
12
+ gem.authors = ["Dan Pickett"]
13
+ gem.add_dependency "activesupport"
14
+ gem.add_dependency "barby"
15
+ gem.add_development_dependency "rspec"
16
+ gem.add_development_dependency "yard"
17
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
+ end
19
+ Jeweler::GemcutterTasks.new
20
+ rescue LoadError
21
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
22
+ end
23
+
24
+ require 'spec/rake/spectask'
25
+ Spec::Rake::SpecTask.new(:spec) do |spec|
26
+ spec.libs << 'lib' << 'spec'
27
+ spec.spec_files = FileList['spec/**/*_spec.rb']
28
+ end
29
+
30
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
31
+ spec.libs << 'lib' << 'spec'
32
+ spec.pattern = 'spec/**/*_spec.rb'
33
+ spec.rcov = true
34
+ end
35
+
36
+ task :spec => :check_dependencies
37
+
38
+ task :default => :spec
39
+
40
+ begin
41
+ require 'yard'
42
+ YARD::Rake::YardocTask.new
43
+ rescue LoadError
44
+ task :yardoc do
45
+ abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
46
+ end
47
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,67 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{has_barcode}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Dan Pickett"]
12
+ s.date = %q{2009-10-05}
13
+ s.description = %q{Nice class method wrapper for Barby}
14
+ s.email = %q{dpickett@enlightsolutions.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "has_barcode.gemspec",
27
+ "lib/has_barcode.rb",
28
+ "lib/has_barcode/configuration.rb",
29
+ "spec/has_barcode/configuration_spec.rb",
30
+ "spec/has_barcode_spec.rb",
31
+ "spec/models/has_png_barcode.rb",
32
+ "spec/spec_helper.rb"
33
+ ]
34
+ s.homepage = %q{http://github.com/dpickett/has_barcode}
35
+ s.rdoc_options = ["--charset=UTF-8"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = %q{1.3.5}
38
+ s.summary = %q{Nice class method wrapper for Barby}
39
+ s.test_files = [
40
+ "spec/has_barcode/configuration_spec.rb",
41
+ "spec/has_barcode_spec.rb",
42
+ "spec/models/has_png_barcode.rb",
43
+ "spec/spec_helper.rb"
44
+ ]
45
+
46
+ if s.respond_to? :specification_version then
47
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
48
+ s.specification_version = 3
49
+
50
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
51
+ s.add_runtime_dependency(%q<activesupport>, [">= 0"])
52
+ s.add_runtime_dependency(%q<barby>, [">= 0"])
53
+ s.add_development_dependency(%q<rspec>, [">= 0"])
54
+ s.add_development_dependency(%q<yard>, [">= 0"])
55
+ else
56
+ s.add_dependency(%q<activesupport>, [">= 0"])
57
+ s.add_dependency(%q<barby>, [">= 0"])
58
+ s.add_dependency(%q<rspec>, [">= 0"])
59
+ s.add_dependency(%q<yard>, [">= 0"])
60
+ end
61
+ else
62
+ s.add_dependency(%q<activesupport>, [">= 0"])
63
+ s.add_dependency(%q<barby>, [">= 0"])
64
+ s.add_dependency(%q<rspec>, [">= 0"])
65
+ s.add_dependency(%q<yard>, [">= 0"])
66
+ end
67
+ end
@@ -0,0 +1,17 @@
1
+ module HasBarcode
2
+ class Configuration
3
+ attr_reader :name, :barcode_class, :outputter_class
4
+ def initialize(*args)
5
+ opts = args.extract_options!
6
+ opts.symbolize_keys!
7
+
8
+ @name = args.first
9
+ @barcode_class = Barby.const_get("#{opts[:type].to_s.classify}")
10
+
11
+ require "barby/outputter/#{opts[:outputter]}_outputter"
12
+ @outputter = Barby.const_get("#{opts[:outputter]}_outputter".classify)
13
+ end
14
+
15
+
16
+ end
17
+ end
@@ -0,0 +1,33 @@
1
+ require "rubygems"
2
+ require "active_support"
3
+ require "barby"
4
+
5
+ require "has_barcode/configuration"
6
+
7
+ module HasBarcode
8
+ def self.included(base)
9
+ base.send(:extend, ClassMethods)
10
+ end
11
+
12
+ module ClassMethods
13
+ def has_barcode(*args)
14
+ options = args.extract_options!
15
+ @@barcode_configurations ||= {}
16
+ @@barcode_configurations[args.first] = HasBarcode::Configuration.new(options)
17
+
18
+ define_method args.first do
19
+ @@barcode_configurations[args.first].barcode_class.new(options[:value].call(self))
20
+ end
21
+
22
+ define_method "#{args.first}_data" do
23
+ send(args.first).send("to_#{options[:outputter]}")
24
+ end
25
+
26
+ end
27
+
28
+ def barcode_configurations
29
+ @@barcode_configurations
30
+ end
31
+ end
32
+
33
+ end
@@ -0,0 +1,24 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "a barcode configuration" do
4
+ before(:each) do
5
+ @configuration = HasBarcode::Configuration.new(:barcode,
6
+ :outputter => :png,
7
+ :type => :code_39
8
+ )
9
+ end
10
+
11
+ it "should have a name" do
12
+ @configuration.name.should_not be_nil
13
+ @configuration.name.should eql(:barcode)
14
+ end
15
+
16
+ it "should have a barcode class" do
17
+ @configuration.barcode_class.should eql(Barby::Code39)
18
+ end
19
+
20
+ it "should have an outputter" do
21
+
22
+ end
23
+ end
24
+
@@ -0,0 +1,32 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "A class that has a barcode" do
4
+ before(:each) do
5
+ @model = HasPngBarcode.new
6
+ end
7
+
8
+ it "should have a barcode configuration" do
9
+ @model.class.barcode_configurations.should_not be_nil
10
+ @model.class.barcode_configurations[:barcode].should_not be_nil
11
+ end
12
+
13
+ end
14
+
15
+ describe "an instance that has a barcode" do
16
+ before(:each) do
17
+ @model = HasPngBarcode.new
18
+ end
19
+
20
+ it "should have a barcode" do
21
+ @model.barcode.should_not be_nil
22
+ @model.barcode.should be_kind_of(Barby::Barcode)
23
+ end
24
+
25
+ it "should have a barcode with a value defined by a proc" do
26
+ @model.barcode.to_s.should eql(@model.random_string_of_numbers)
27
+ end
28
+
29
+ it "should have barcode data that corresponds to the outputter" do
30
+ @model.barcode_data.should eql(Barby::Code39.new(@model.random_string_of_numbers).to_png)
31
+ end
32
+ end
@@ -0,0 +1,17 @@
1
+ class HasPngBarcode
2
+ include HasBarcode
3
+
4
+ has_barcode :barcode,
5
+ :outputter => :png,
6
+ :type => :code_39,
7
+ :value => Proc.new{|p| p.random_string_of_numbers}
8
+
9
+ def random_string_of_numbers
10
+ if !@string_of_numbers
11
+ @string_of_numbers = []
12
+ 5.times {@string_of_numbers << rand(9)}
13
+ end
14
+
15
+ @string_of_numbers.join("")
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'has_barcode'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ require 'spec/models/has_png_barcode'
8
+
9
+ Spec::Runner.configure do |config|
10
+
11
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: has_barcode
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dan Pickett
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-05 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activesupport
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: barby
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: rspec
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: yard
47
+ type: :development
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ description: Nice class method wrapper for Barby
56
+ email: dpickett@enlightsolutions.com
57
+ executables: []
58
+
59
+ extensions: []
60
+
61
+ extra_rdoc_files:
62
+ - LICENSE
63
+ - README.rdoc
64
+ files:
65
+ - .document
66
+ - .gitignore
67
+ - LICENSE
68
+ - README.rdoc
69
+ - Rakefile
70
+ - VERSION
71
+ - has_barcode.gemspec
72
+ - lib/has_barcode.rb
73
+ - lib/has_barcode/configuration.rb
74
+ - spec/has_barcode/configuration_spec.rb
75
+ - spec/has_barcode_spec.rb
76
+ - spec/models/has_png_barcode.rb
77
+ - spec/spec_helper.rb
78
+ has_rdoc: true
79
+ homepage: http://github.com/dpickett/has_barcode
80
+ licenses: []
81
+
82
+ post_install_message:
83
+ rdoc_options:
84
+ - --charset=UTF-8
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: "0"
92
+ version:
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: "0"
98
+ version:
99
+ requirements: []
100
+
101
+ rubyforge_project:
102
+ rubygems_version: 1.3.5
103
+ signing_key:
104
+ specification_version: 3
105
+ summary: Nice class method wrapper for Barby
106
+ test_files:
107
+ - spec/has_barcode/configuration_spec.rb
108
+ - spec/has_barcode_spec.rb
109
+ - spec/models/has_png_barcode.rb
110
+ - spec/spec_helper.rb