open-ship 0.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG ADDED
@@ -0,0 +1 @@
1
+ v0.1. first version
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2011 Nathan Smith
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
22
+
data/Manifest ADDED
@@ -0,0 +1,11 @@
1
+ CHANGELOG
2
+ LICENSE
3
+ Manifest
4
+ README
5
+ Rakefile
6
+ lib/openship.rb
7
+ lib/openship/label.rb
8
+ lib/openship/openship.rb
9
+ lib/openship/sscc.rb
10
+ spec/openship/sscc_spec.rb
11
+ spec/spec_helper.rb
data/README ADDED
@@ -0,0 +1 @@
1
+ A library to make the hard parts of commercial shipping a little easier.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require 'echoe'
2
+
3
+ Echoe.new('open-ship') do |p|
4
+ p.author = "Nathan Smith"
5
+ p.email = "nathansmith22@gmail.com"
6
+ p.summary = "Shipments for the rest of us."
7
+ p.description = "A library to make the hard parts of commercial shipping a little easier."
8
+
9
+ p.runtime_dependencies = ["barby >=0.4.2", "prawn >=0.11.1"]
10
+ end
11
+
12
+
@@ -0,0 +1,7 @@
1
+ module OpenShip
2
+
3
+ class Label
4
+
5
+ end
6
+
7
+ end
@@ -0,0 +1,3 @@
1
+ module OpenShip
2
+
3
+ end
@@ -0,0 +1,67 @@
1
+ module OpenShip
2
+
3
+ class Sscc
4
+
5
+ @company_prefix
6
+ @extension_digit = "1"
7
+
8
+ def self.company_prefix
9
+ @company_prefix
10
+ end
11
+
12
+ def self.company_prefix=(prefix)
13
+ if !prefix.start_with? "0"
14
+ raise "Company prefix should have a leading zero."
15
+ end
16
+ @company_prefix=prefix
17
+ end
18
+
19
+ def self.extension_digit
20
+ @extension_digit
21
+ end
22
+
23
+ def self.extension_digit=(digit)
24
+ @extension_digit = digit
25
+ end
26
+
27
+ def self.generate_check_digit(string_sequence)
28
+ # It's gotta be a string because of the leading zero possibility
29
+ # in the extension digit.
30
+ unless string_sequence.class <= String
31
+ raise "Can only check string sequences."
32
+ end
33
+ unless string_sequence.length == 17
34
+ raise "Sequence must be 17 characters long"
35
+ end
36
+ sequence = []
37
+ string_sequence.each_char { |chr|
38
+ sequence << chr.to_i
39
+ }
40
+
41
+ # See http://www.gs1us.org/solutions_services/tools/check_digit_calculator
42
+ array1 = [sequence[0], sequence[2], sequence[4], sequence[6],
43
+ sequence[8], sequence[10], sequence[12], sequence[14], sequence[16]]
44
+ number1 = (array1.inject(:+) * 3)
45
+ array2 = [sequence[1], sequence[3], sequence[5], sequence[7], sequence[9],
46
+ sequence[11], sequence[13], sequence[15]]
47
+ number2 = array2.inject(:+)
48
+ number3 = number1 + number2
49
+ check_digit = (10 - (number3 % 10)).to_s
50
+ end
51
+
52
+ def self.generate_sscc_id(serial_reference)
53
+ if company_prefix.nil?
54
+ raise "Company prefix cannot be nil. Set with OpenShip::Sscc.company_prefix"
55
+ end
56
+ while ((@company_prefix.length + serial_reference.length) < 16)
57
+ serial_reference = "0" + serial_reference
58
+ end
59
+ sequence = @extension_digit + @company_prefix + serial_reference
60
+ check_digit = self.generate_check_digit(sequence)
61
+ sscc = sequence + check_digit
62
+ end
63
+
64
+
65
+ end
66
+
67
+ end
data/lib/openship.rb ADDED
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH << File.dirname(__FILE__) unless $LOAD_PATH.include?(File.dirname(__FILE__))
2
+
3
+ module OpenShip
4
+
5
+ end
6
+
7
+ require 'openship'
8
+ require 'openship/sscc'
9
+
data/open-ship.gemspec ADDED
@@ -0,0 +1,38 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{open-ship}
5
+ s.version = "0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Nathan Smith"]
9
+ s.cert_chain = ["/Users/nsmith/.ssh/gem-public_cert.pem"]
10
+ s.date = %q{2011-05-05}
11
+ s.description = %q{A library to make the hard parts of commercial shipping a little easier.}
12
+ s.email = %q{nathansmith22@gmail.com}
13
+ s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README", "lib/openship.rb", "lib/openship/label.rb", "lib/openship/openship.rb", "lib/openship/sscc.rb"]
14
+ s.files = ["CHANGELOG", "LICENSE", "Manifest", "README", "Rakefile", "lib/openship.rb", "lib/openship/label.rb", "lib/openship/openship.rb", "lib/openship/sscc.rb", "spec/openship/sscc_spec.rb", "spec/spec_helper.rb", "open-ship.gemspec"]
15
+ s.homepage = %q{http://open-ship.github.com/open-ship/}
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Open-ship", "--main", "README"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{open-ship}
19
+ s.rubygems_version = %q{1.3.6}
20
+ s.signing_key = %q{/Users/nsmith/.ssh/gem-private_key.pem}
21
+ s.summary = %q{Shipments for the rest of us.}
22
+
23
+ if s.respond_to? :specification_version then
24
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
+ s.specification_version = 3
26
+
27
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
28
+ s.add_runtime_dependency(%q<barby>, [">= 0.4.2"])
29
+ s.add_runtime_dependency(%q<prawn>, [">= 0.11.1"])
30
+ else
31
+ s.add_dependency(%q<barby>, [">= 0.4.2"])
32
+ s.add_dependency(%q<prawn>, [">= 0.11.1"])
33
+ end
34
+ else
35
+ s.add_dependency(%q<barby>, [">= 0.4.2"])
36
+ s.add_dependency(%q<prawn>, [">= 0.11.1"])
37
+ end
38
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe OpenShip::Sscc do
4
+
5
+ it "Should persist a company prefix on the model" do
6
+ OpenShip::Sscc.company_prefix = "0801234"
7
+ OpenShip::Sscc.company_prefix.should == "0801234"
8
+ end
9
+
10
+ it "should generate a valid check digit for a given sscc id" do
11
+ # See http://www.gs1us.org/solutions_services/tools/check_digit_calculator
12
+ # for the example from which this is derived.
13
+ sscc = "10614141192837465"
14
+ sscc2 = "10614141192837700"
15
+ expected_digit = "7"
16
+ expected_digit2 = "9"
17
+ OpenShip::Sscc.generate_check_digit(sscc).should == expected_digit
18
+ OpenShip::Sscc.generate_check_digit(sscc2).should == expected_digit2
19
+ end
20
+
21
+ it "should return a valid sscc for a sequence number" do
22
+ company_prefix = "0614141"
23
+ serial_reference = "192837465"
24
+ OpenShip::Sscc.company_prefix = company_prefix
25
+ sscc = OpenShip::Sscc.generate_sscc_id(serial_reference)
26
+ sscc.should == "106141411928374657"
27
+ end
28
+
29
+ it "should fill in leading zeros in serial_reference if serial_reference + company_prefix + extension_digit adds up to less than 17" do
30
+ company_prefix = "0614141"
31
+ serial_reference = "1"
32
+ OpenShip::Sscc.company_prefix = company_prefix
33
+ sscc = OpenShip::Sscc.generate_sscc_id(serial_reference)
34
+ sscc.length.should == 18
35
+ sscc.should match /0{8}/
36
+ end
37
+
38
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec/autorun'
2
+
3
+ require 'openship'
4
+
5
+ Spec::Runner.configure do |config|
6
+
7
+ end
data.tar.gz.sig ADDED
@@ -0,0 +1 @@
1
+ �A�/l� R� ���i(���r}v�'�+`�hw�Gj�t�2f��/���P���|����HS������UU- s��Ӡ �m͟���<,�h��!h� ���ֻ�fc"=�[�ʃ=��O��:V���a
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: open-ship
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ version: "0.1"
9
+ platform: ruby
10
+ authors:
11
+ - Nathan Smith
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain:
15
+ - |
16
+ -----BEGIN CERTIFICATE-----
17
+ MIIDPDCCAiSgAwIBAgIBADANBgkqhkiG9w0BAQUFADBEMRYwFAYDVQQDDA1uYXRo
18
+ YW5zbWl0aDIyMRUwEwYKCZImiZPyLGQBGRYFZ21haWwxEzARBgoJkiaJk/IsZAEZ
19
+ FgNjb20wHhcNMTEwNTA1MDAzNjM4WhcNMTIwNTA0MDAzNjM4WjBEMRYwFAYDVQQD
20
+ DA1uYXRoYW5zbWl0aDIyMRUwEwYKCZImiZPyLGQBGRYFZ21haWwxEzARBgoJkiaJ
21
+ k/IsZAEZFgNjb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCmITKp
22
+ K5dZtKP+ufjCpswNoHeefgp7QgbGlRiq/oeygMIeF4bKlfPLaEelB1kWSVJt/9na
23
+ 0LOnj5VEj2T3hOxGMfQfbi+JSw4F1JgCWbygSmbLOIqx26RSdwtXRlucU75MtiJw
24
+ 6YRwL0Z4EN54/Gz6YKdihIHpaVukAHFxAqTud7yKhLqmSxLYxFprCSHAeYvne/jy
25
+ Sapn4gxpPclL5704W9AwM2hPXhzJDaoZ9FeDLrnJFLmaOwNjrfeeL80KY3yhCL2J
26
+ WFQrRv6x3bisoncQdCPGrXf43S1Feho/tnH36nmaWfOPjHeuMl7EETQ1j9E9mWXp
27
+ 2mWTuS5UL3JESFs9AgMBAAGjOTA3MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0G
28
+ A1UdDgQWBBQO4xvpiOZ9ET10Oa/Papw7lBNOMjANBgkqhkiG9w0BAQUFAAOCAQEA
29
+ AYSPAXtPVPKYEquYbh9awP0PJ0Gm58Idbw9XcjDdObZdc94C9UDOvYSVogJEV/21
30
+ kdwIexLZAPISam73xeqpameKk4NF/m0MpuCySage6LM2rvwBmn3WVE8RHR9iecMI
31
+ 7I5gTqiGRXNWgY8ZTV8v4HA3Fjzlt1/pfNgIuoCHVAYEcY8+SDDhNdw+ds3gP1Hs
32
+ Os0rPuluBZPWJ1I9ABhC44WVW3tkbureDH7QF5XyTUgG3jmjM3LB8Rdx8Tudbkxd
33
+ Z8Zd52B2nwdJM3AMs3A32GBTxRZ/EHhtOY75kEEyNiVItNIVCruEAM604unwPEjN
34
+ aCwdDbQuC7JfdDETk+jeNA==
35
+ -----END CERTIFICATE-----
36
+
37
+ date: 2011-05-05 00:00:00 -04:00
38
+ default_executable:
39
+ dependencies:
40
+ - !ruby/object:Gem::Dependency
41
+ name: barby
42
+ prerelease: false
43
+ requirement: &id001 !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ segments:
48
+ - 0
49
+ - 4
50
+ - 2
51
+ version: 0.4.2
52
+ type: :runtime
53
+ version_requirements: *id001
54
+ - !ruby/object:Gem::Dependency
55
+ name: prawn
56
+ prerelease: false
57
+ requirement: &id002 !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ segments:
62
+ - 0
63
+ - 11
64
+ - 1
65
+ version: 0.11.1
66
+ type: :runtime
67
+ version_requirements: *id002
68
+ description: A library to make the hard parts of commercial shipping a little easier.
69
+ email: nathansmith22@gmail.com
70
+ executables: []
71
+
72
+ extensions: []
73
+
74
+ extra_rdoc_files:
75
+ - CHANGELOG
76
+ - LICENSE
77
+ - README
78
+ - lib/openship.rb
79
+ - lib/openship/label.rb
80
+ - lib/openship/openship.rb
81
+ - lib/openship/sscc.rb
82
+ files:
83
+ - CHANGELOG
84
+ - LICENSE
85
+ - Manifest
86
+ - README
87
+ - Rakefile
88
+ - lib/openship.rb
89
+ - lib/openship/label.rb
90
+ - lib/openship/openship.rb
91
+ - lib/openship/sscc.rb
92
+ - spec/openship/sscc_spec.rb
93
+ - spec/spec_helper.rb
94
+ - open-ship.gemspec
95
+ has_rdoc: true
96
+ homepage: http://open-ship.github.com/open-ship/
97
+ licenses: []
98
+
99
+ post_install_message:
100
+ rdoc_options:
101
+ - --line-numbers
102
+ - --inline-source
103
+ - --title
104
+ - Open-ship
105
+ - --main
106
+ - README
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ segments:
114
+ - 0
115
+ version: "0"
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ segments:
121
+ - 1
122
+ - 2
123
+ version: "1.2"
124
+ requirements: []
125
+
126
+ rubyforge_project: open-ship
127
+ rubygems_version: 1.3.6
128
+ signing_key:
129
+ specification_version: 3
130
+ summary: Shipments for the rest of us.
131
+ test_files: []
132
+
metadata.gz.sig ADDED
Binary file