jan 0.0.3 → 0.0.4
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.
- checksums.yaml +4 -4
- data/lib/jan/check_digit_calculator.rb +1 -1
- data/lib/jan/parser.rb +2 -2
- data/lib/jan/random.rb +2 -2
- data/lib/jan/validator.rb +1 -1
- data/lib/jan/version.rb +2 -2
- data/lib/jan.rb +11 -13
- data/spec/jan_spec.rb +27 -37
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 08c3cfeccb0e7c251771a361c3a06fcd54b98937
|
4
|
+
data.tar.gz: c20f6fd40652e7dbe919637f0d267fd6bc5fc394
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e9eae526ddf5131d130e4f53063734c79cde4c504941c5112308718a24cbb56aeb6585356313a621bb9786c82d58c8749f0dcf4a2088cb4b6a8d59cb1bb55e4
|
7
|
+
data.tar.gz: 3187307e507e10caf0e8107cec9905829206ab037840e5601ad6a7c689d5b3b8388c07b3ab8c509dbe4dd000790349fb2605abe400976cf2cbeca6ad2b84cae3
|
data/lib/jan/parser.rb
CHANGED
data/lib/jan/random.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "jan/parser"
|
2
2
|
require "jan/check_digit_calculator"
|
3
3
|
|
4
|
-
class Jan
|
4
|
+
class Jan < ::String
|
5
5
|
module Random
|
6
6
|
module_function
|
7
7
|
|
@@ -12,7 +12,7 @@ class Jan
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def instore_code(size=13)
|
15
|
-
build(size - 2,
|
15
|
+
build(size - 2, InstoreCodePrefixes.sample)
|
16
16
|
end
|
17
17
|
|
18
18
|
def build(size, code="")
|
data/lib/jan/validator.rb
CHANGED
data/lib/jan/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
class Jan
|
2
|
-
VERSION = "0.0.
|
1
|
+
class Jan < ::String
|
2
|
+
VERSION = "0.0.4"
|
3
3
|
end
|
data/lib/jan.rb
CHANGED
@@ -1,35 +1,33 @@
|
|
1
|
-
require "jan/version"
|
2
|
-
require "jan/parser"
|
3
1
|
require "jan/check_digit_calculator"
|
4
|
-
require "jan/
|
2
|
+
require "jan/parser"
|
5
3
|
require "jan/random"
|
4
|
+
require "jan/validator"
|
5
|
+
require "jan/version"
|
6
6
|
|
7
|
-
class Jan
|
8
|
-
|
9
|
-
|
10
|
-
attr_accessor :code
|
7
|
+
class Jan < ::String
|
8
|
+
InstoreCodePrefixes = %w(02 20 21 22 23 24 25 26 27 28 29)
|
11
9
|
|
12
10
|
def initialize(code)
|
13
|
-
|
11
|
+
super(code.to_s)
|
14
12
|
end
|
15
13
|
|
16
14
|
def valid?
|
17
|
-
Validator.validate(
|
15
|
+
Validator.validate(self)
|
18
16
|
end
|
19
17
|
|
20
18
|
def check_digit
|
21
|
-
Parser.check_digit(
|
19
|
+
Parser.check_digit(self)
|
22
20
|
end
|
23
21
|
|
24
22
|
def even_digits
|
25
|
-
Parser.even_digits(
|
23
|
+
Parser.even_digits(self)
|
26
24
|
end
|
27
25
|
|
28
26
|
def odd_digits
|
29
|
-
Parser.odd_digits(
|
27
|
+
Parser.odd_digits(self)
|
30
28
|
end
|
31
29
|
|
32
30
|
def instore_code?
|
33
|
-
Parser.instore_code?(
|
31
|
+
Parser.instore_code?(self)
|
34
32
|
end
|
35
33
|
end
|
data/spec/jan_spec.rb
CHANGED
@@ -1,67 +1,57 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Jan do
|
4
|
+
describe "#initialize" do
|
5
|
+
let(:jan_code){ "4901085089347" }
|
6
|
+
subject{ described_class.new(jan_code) }
|
7
|
+
it{ is_expected.to be_an_instance_of(described_class) }
|
8
|
+
it{ is_expected.to be_a(String) }
|
9
|
+
it("should equals to given string"){ is_expected.to eq(jan_code) }
|
10
|
+
end
|
11
|
+
|
4
12
|
describe "#valid?" do
|
5
13
|
context "valid codes" do
|
6
|
-
valid_codes.each do |
|
7
|
-
|
8
|
-
|
9
|
-
expect(jan.valid?).to be true
|
10
|
-
end
|
14
|
+
valid_codes.each do |valid_code|
|
15
|
+
subject{ described_class.new(valid_code) }
|
16
|
+
it("#{valid_code} should be valid"){ is_expected.to be_valid }
|
11
17
|
end
|
12
18
|
end
|
13
19
|
|
14
20
|
context "invalid codes" do
|
15
|
-
invalid_codes.each do |
|
16
|
-
|
17
|
-
|
18
|
-
expect(jan.valid?).to be false
|
19
|
-
end
|
21
|
+
invalid_codes.each do |invalid_code|
|
22
|
+
subject{ described_class.new(invalid_code) }
|
23
|
+
it("#{invalid_code} should be invalid"){ is_expected.not_to be_valid }
|
20
24
|
end
|
21
25
|
end
|
22
26
|
end
|
23
27
|
|
24
28
|
describe "#check_digit" do
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
29
|
+
let(:jan){ described_class.new("4901277241126") }
|
30
|
+
subject{ jan.check_digit }
|
31
|
+
it("should return last digit"){ is_expected.to eq(6) }
|
29
32
|
end
|
30
33
|
|
31
34
|
describe "#even_digits" do
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
end
|
35
|
+
let(:jan){ described_class.new("4901277241126") }
|
36
|
+
subject{ jan.even_digits }
|
37
|
+
it("should return digits in even number-th position"){ is_expected.to eq([9,1,7,2,1,2]) }
|
36
38
|
end
|
37
39
|
|
38
40
|
describe "#odd_digits" do
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe "#instore_code?" do
|
46
|
-
it "should return digits in odd number-th position except check digit" do
|
47
|
-
jan = Jan.new("4901277241126")
|
48
|
-
expect(jan.odd_digits).to eq([4,0,2,7,4,1])
|
49
|
-
end
|
41
|
+
let(:jan){ described_class.new("4901277241126") }
|
42
|
+
subject{ jan.odd_digits }
|
43
|
+
it("should return digits in odd number-th position except check digit"){ is_expected.to eq([4,0,2,7,4,1]) }
|
50
44
|
end
|
51
45
|
|
52
46
|
describe "#instore_code?" do
|
53
47
|
context "instore code" do
|
54
|
-
|
55
|
-
|
56
|
-
expect(jan).to be_instore_code
|
57
|
-
end
|
48
|
+
subject{ described_class.new("2101085089347") }
|
49
|
+
it("should be true"){ is_expected.to be_instore_code }
|
58
50
|
end
|
59
51
|
|
60
52
|
context "global code" do
|
61
|
-
|
62
|
-
|
63
|
-
expect(jan).not_to be_instore_code
|
64
|
-
end
|
53
|
+
subject{ described_class.new("4901085089347") }
|
54
|
+
it("should be false"){ is_expected.not_to be_instore_code }
|
65
55
|
end
|
66
56
|
end
|
67
57
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- OSA Shunsuke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|