intermodal_container_check_digit_calculator 0.0.2

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e5da963ec8fcc4b9048f855febd473fc4613d146
4
+ data.tar.gz: 70a37ce9ecbe3e5b8c5f0b8b31ea09ff477786a8
5
+ SHA512:
6
+ metadata.gz: 80e9c804722c790016bfa9047a3d00d8945eec45ea39e4c4d72746a3e076a7573f301fa5cff5abd1487fe6812828c6fb6268b29004b1099c8c5edea0b8e62eec
7
+ data.tar.gz: 517e9c366ddba3a3f746569f2b0e98a7413b3fecad4763cf5ea2f0ccd2a41fb70ac91ebab302157bad8489eaa08e691ec6f0b5ef1c42ca3dbbc5e5313f839076
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Tom Piekos
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,43 @@
1
+ # Intermodal Container Check Digit Calculator
2
+
3
+ This gem facilitates simple calculation of check digits on [intermodal shipping containers](https://en.wikipedia.org/wiki/Intermodal_container).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'intermodal_container_check_digit_calculator'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install intermodal_container_check_digit_calculator
18
+
19
+ ## Usage
20
+
21
+ ```Ruby
22
+ prefix = "TOMU"
23
+ serial = "123456"
24
+
25
+ IntermodalContainerCheckDigitCalculator::Calculator.calculate(prefix, serial)
26
+ # => "5"
27
+ ```
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create new Pull Request
36
+
37
+ ## About Foraker Labs
38
+
39
+ <img src="http://assets.foraker.com/foraker_logo.png" width="400" height="62">
40
+
41
+ This project is maintained by Foraker Labs. The names and logos of Foraker Labs are fully owned and copyright Foraker Design, LLC.
42
+
43
+ Foraker Labs is a Boulder-based Ruby on Rails and iOS development shop. Please reach out if we can [help build your product](http://www.foraker.com).
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'intermodal_container_check_digit_calculator/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "intermodal_container_check_digit_calculator"
8
+ spec.version = IntermodalContainerCheckDigitCalculator::VERSION
9
+ spec.authors = ["Tom Piekos"]
10
+ spec.email = ["tep@foraker.com"]
11
+ spec.summary = %q{Facilitates check digit calculation for intermodal shipping containers.}
12
+ spec.description = %q{Facilitates check digit calculation for intermodal shipping containers.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "activesupport"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.9"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec"
26
+ end
@@ -0,0 +1,95 @@
1
+ require 'intermodal_container_check_digit_calculator/version'
2
+ require 'active_support'
3
+ require 'active_support/core_ext'
4
+
5
+ module IntermodalContainerCheckDigitCalculator
6
+ class Calculator
7
+ attr_reader :assigned_values
8
+
9
+ DIVISOR = 11.0
10
+
11
+ def self.calculate(prefix, serial)
12
+ new(prefix + serial).calculate
13
+ end
14
+
15
+ def initialize(number)
16
+ @number = number
17
+ end
18
+
19
+ def calculate
20
+ (difference % 10).to_s
21
+ end
22
+
23
+ private
24
+
25
+ attr_reader :number
26
+
27
+ def difference
28
+ @difference ||= sum - floored_sum
29
+ end
30
+
31
+ def sum
32
+ @sum ||= characters.sum(&:value)
33
+ end
34
+
35
+ def floored_sum
36
+ (((sum/DIVISOR).floor) * DIVISOR).to_i
37
+ end
38
+
39
+ def characters
40
+ number.each_char.map.with_index{ |c, i| Character.new(c, i) }
41
+ end
42
+ end
43
+
44
+ class Character
45
+ attr_reader :character, :index
46
+
47
+ ALPHA_VALUES = {
48
+ 'A' => 10,
49
+ 'B' => 12,
50
+ 'C' => 13,
51
+ 'D' => 14,
52
+ 'E' => 15,
53
+ 'F' => 16,
54
+ 'G' => 17,
55
+ 'H' => 18,
56
+ 'I' => 19,
57
+ 'J' => 20,
58
+ 'K' => 21,
59
+ 'L' => 23,
60
+ 'M' => 24,
61
+ 'N' => 25,
62
+ 'O' => 26,
63
+ 'P' => 27,
64
+ 'Q' => 28,
65
+ 'R' => 29,
66
+ 'S' => 30,
67
+ 'T' => 31,
68
+ 'U' => 32,
69
+ 'V' => 34,
70
+ 'W' => 35,
71
+ 'X' => 36,
72
+ 'Y' => 37,
73
+ 'Z' => 38
74
+ }
75
+
76
+ def initialize(character, index)
77
+ @character = character.upcase
78
+ @index = index
79
+ end
80
+
81
+ def value
82
+ alpha_value * exponent
83
+ end
84
+
85
+ private
86
+
87
+ def exponent
88
+ 2 ** index
89
+ end
90
+
91
+ def alpha_value
92
+ ALPHA_VALUES.fetch(character, character.to_i)
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,3 @@
1
+ module IntermodalContainerCheckDigitCalculator
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,31 @@
1
+ require 'active_support'
2
+ require 'active_support/core_ext'
3
+ require 'intermodal_container_check_digit_calculator'
4
+
5
+ module IntermodalContainerCheckDigitCalculator
6
+ describe Calculator do
7
+ describe ".calculate" do
8
+ test_cases =
9
+ [
10
+ {prefix: "CSQU", serial: "305438", output: "3"},
11
+ {prefix: "ABCD", serial: "123456", output: "0"},
12
+ {prefix: "DEFG", serial: "768901", output: "7"},
13
+ {prefix: "HIJK", serial: "234567", output: "2"},
14
+ {prefix: "LMNO", serial: "890123", output: "1"},
15
+ {prefix: "PQRS", serial: "456789", output: "8"},
16
+ {prefix: "TUVW", serial: "012345", output: "8"},
17
+ {prefix: "XYZA", serial: "678901", output: "0"}
18
+ ]
19
+
20
+ test_cases.each do |test_case|
21
+ it "should correctly calculate a checksum with #{test_case[:prefix]}#{test_case[:serial]}" do
22
+ calculate(test_case[:prefix], test_case[:serial], test_case[:output])
23
+ end
24
+ end
25
+ end
26
+
27
+ def calculate(prefix, serial, output)
28
+ expect(described_class.calculate(prefix, serial)).to eq(output)
29
+ end
30
+ end
31
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: intermodal_container_check_digit_calculator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Tom Piekos
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.9'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Facilitates check digit calculation for intermodal shipping containers.
70
+ email:
71
+ - tep@foraker.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - intermodal_container_check_digit_calculator.gemspec
83
+ - lib/intermodal_container_check_digit_calculator.rb
84
+ - lib/intermodal_container_check_digit_calculator/version.rb
85
+ - spec/intermodal_container_check_digit_calculator_spec.rb
86
+ homepage: ''
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.4.8
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: Facilitates check digit calculation for intermodal shipping containers.
110
+ test_files:
111
+ - spec/intermodal_container_check_digit_calculator_spec.rb