jan 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e0effbb542c76db5c76ab38d7edc9a95e56aa47985b7d3f481aa4799629e4e02
4
- data.tar.gz: 57c8f87ea36fe989cae817baa2d04981c28e723a838a848ea1672f35a24c8480
3
+ metadata.gz: 7b9f59ef9f5c098027f2bcce1c1d0274d441405ef3c815ca1add5ea85bc1c062
4
+ data.tar.gz: 44e0a9c709e86f11dd83f58b5e56579e731ac94883900da6d09bd798218b6ee3
5
5
  SHA512:
6
- metadata.gz: cdb58db78040e27e525980eb5ea32c30cb38f3f31f60dedb87c5f57f39b5bd0acc2fcd9431a60bbd4566969c199c0bed2c8b08fc2ac3a3c1b57e47ad37105e63
7
- data.tar.gz: 4efe19db1d9cacbea44eb314096e45d08f0f5d537104f8a0964153f554c4077f022e0a400385bac4f3561944f32045b6857acc4d8951b5d048f15297949f015d
6
+ metadata.gz: 2b9587535d3fa03d7a4b107f226aad058e7209a6b2a58b61e1420743e26006bc400ddd4f4eac9ad9e5111db8488a719b041fad9800fba9577e1129161b6290d5
7
+ data.tar.gz: afc558ce893d95fb4b06307eedc20d6e90e20b3da43421c46dbda24e5c4239988c4f8b5701282e0a650093cd3669920a2ed4b449d265c02e1fd83698ef993f06
@@ -25,8 +25,17 @@ module Jan
25
25
 
26
26
  # @return [Array<String>]
27
27
  def codepoints
28
- additional_digit, *digits = @code.each_char.to_a
29
- variable_parity_encodation_sequence(additional_digit).zip(digits).map(&:join)
28
+ case @code.length
29
+ when 13
30
+ additional_digit, *digits = @code.each_char.to_a
31
+ variable_parity_encodation_sequence(additional_digit).zip(digits).map(&:join)
32
+ when 8
33
+ digits = @code.each_char.to_a
34
+ parity_encodation_sequence = %w[A A A A C C C C]
35
+ parity_encodation_sequence.zip(digits).map(&:join)
36
+ else
37
+ raise 'Invalid code length (code must be 13-digit or 8 digit)'
38
+ end
30
39
  end
31
40
 
32
41
  # EXPERIMENTAL
@@ -34,12 +43,13 @@ module Jan
34
43
  # @return [String]
35
44
  def svg
36
45
  x = 0
46
+ width = svg_width(@code)
37
47
  height = 60
38
48
 
39
49
  builder = Builder::XmlMarkup.new(indent: 2)
40
50
  builder.instruct!(:xml, version: '1.0', encoding: 'UTF-8')
41
- builder.svg(xmlns: 'http://www.w3.org/2000/svg', width: 113, height: height) do |svg|
42
- svg.rect(x: 0, y: 0, width: 113, height: 60, fill: 'white')
51
+ builder.svg(xmlns: 'http://www.w3.org/2000/svg', width: width, height: height) do |svg|
52
+ svg.rect(x: 0, y: 0, width: width, height: 60, fill: 'white')
43
53
  band_patterns.each do |band_pattern|
44
54
  svg.g(class: band_pattern.class.name.split('::').last) do |group|
45
55
  band_pattern.bands.each do |band|
@@ -55,16 +65,26 @@ module Jan
55
65
 
56
66
  # @return [Array<Jan::Symbol::BandPattern::SymbolCharacter>]
57
67
  def left_symbol_characters
58
- codepoints[0..5].map { |codepoint|
59
- BandPattern::SymbolCharacter.new(codepoint)
60
- }
68
+ case @code.length
69
+ when 13
70
+ codepoints[0..5].map { |codepoint| BandPattern::SymbolCharacter.new(codepoint) }
71
+ when 8
72
+ codepoints[0..3].map { |codepoint| BandPattern::SymbolCharacter.new(codepoint) }
73
+ else
74
+ raise
75
+ end
61
76
  end
62
77
 
63
78
  # @return [Array<Jan::Symbol::BandPattern::SymbolCharacter>]
64
79
  def right_symbol_characters
65
- codepoints[6..11].map { |codepoint|
66
- BandPattern::SymbolCharacter.new(codepoint)
67
- }
80
+ case @code.length
81
+ when 13
82
+ codepoints[6..11].map { |codepoint| BandPattern::SymbolCharacter.new(codepoint) }
83
+ when 8
84
+ codepoints[4..7].map { |codepoint| BandPattern::SymbolCharacter.new(codepoint) }
85
+ else
86
+ raise
87
+ end
68
88
  end
69
89
 
70
90
  # @param digit [String]
@@ -93,5 +113,18 @@ module Jan
93
113
  %w[A B B A B A C C C C C C]
94
114
  end
95
115
  end
116
+
117
+ # @param code [String]
118
+ # @return [Integer]
119
+ def svg_width(code)
120
+ case code.length
121
+ when 13
122
+ 113
123
+ when 8
124
+ 85
125
+ else
126
+ raise
127
+ end
128
+ end
96
129
  end
97
130
  end
@@ -1,3 +1,3 @@
1
1
  module Jan
2
- VERSION = '0.2.3'
2
+ VERSION = '0.2.4'
3
3
  end
@@ -1,18 +1,22 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Jan::Symbol do
4
- let(:symbol) { described_class.new('4901085188033') }
4
+ let(:symbol13) { described_class.new('4901085188033') }
5
+ let(:symbol8) { described_class.new('49377415') }
5
6
 
6
7
  describe 'initializer' do
7
- it { expect(symbol).to be_an_instance_of Jan::Symbol }
8
+ it { expect(symbol13).to be_an_instance_of Jan::Symbol }
9
+ it { expect(symbol8).to be_an_instance_of Jan::Symbol }
8
10
  end
9
11
 
10
12
  describe '#band_patterns' do
11
- it { expect(symbol.band_patterns).to be_an_instance_of Array }
12
- it { expect(symbol.band_patterns).to all( be_an Jan::Symbol::BandPattern) }
13
+ it { expect(symbol13.band_patterns).to be_an_instance_of Array }
14
+ it { expect(symbol8.band_patterns).to be_an_instance_of Array }
15
+ it { expect(symbol13.band_patterns).to all( be_an Jan::Symbol::BandPattern) }
16
+ it { expect(symbol8.band_patterns).to all( be_an Jan::Symbol::BandPattern) }
13
17
 
14
18
  it 'has correct format' do
15
- patterns = symbol.band_patterns
19
+ patterns = symbol13.band_patterns
16
20
 
17
21
  expect(patterns[0]).to be_an_instance_of Jan::Symbol::BandPattern::LeftQuietZone
18
22
  expect(patterns[1]).to be_an_instance_of Jan::Symbol::BandPattern::NormalGuardPattern
@@ -21,6 +25,16 @@ describe Jan::Symbol do
21
25
  expect(patterns[9..14]).to all( be_an Jan::Symbol::BandPattern::SymbolCharacter )
22
26
  expect(patterns[15]).to be_an_instance_of Jan::Symbol::BandPattern::NormalGuardPattern
23
27
  expect(patterns[16]).to be_an_instance_of Jan::Symbol::BandPattern::RightQuietZone
28
+
29
+ patterns = symbol8.band_patterns
30
+
31
+ expect(patterns[0]).to be_an_instance_of Jan::Symbol::BandPattern::LeftQuietZone
32
+ expect(patterns[1]).to be_an_instance_of Jan::Symbol::BandPattern::NormalGuardPattern
33
+ expect(patterns[2..5]).to all( be_an Jan::Symbol::BandPattern::SymbolCharacter )
34
+ expect(patterns[6]).to be_an_instance_of Jan::Symbol::BandPattern::CenterGuardPattern
35
+ expect(patterns[7..10]).to all( be_an Jan::Symbol::BandPattern::SymbolCharacter )
36
+ expect(patterns[11]).to be_an_instance_of Jan::Symbol::BandPattern::NormalGuardPattern
37
+ expect(patterns[12]).to be_an_instance_of Jan::Symbol::BandPattern::RightQuietZone
24
38
  end
25
39
  end
26
40
 
@@ -36,6 +50,7 @@ describe Jan::Symbol do
36
50
  '7123456789012' => %w[A1 B2 A3 B4 A5 B6 C7 C8 C9 C0 C1 C2],
37
51
  '8123456789012' => %w[A1 B2 A3 B4 B5 A6 C7 C8 C9 C0 C1 C2],
38
52
  '9123456789012' => %w[A1 B2 B3 A4 B5 A6 C7 C8 C9 C0 C1 C2],
53
+ '12345678' => %w[A1 A2 A3 A4 C5 C6 C7 C8],
39
54
  }
40
55
 
41
56
  mappings.each do |code, answer|
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.2.3
4
+ version: 0.2.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: 2019-04-20 00:00:00.000000000 Z
11
+ date: 2019-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: builder
@@ -128,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
128
  - !ruby/object:Gem::Version
129
129
  version: '0'
130
130
  requirements: []
131
- rubygems_version: 3.0.1
131
+ rubygems_version: 3.0.3
132
132
  signing_key:
133
133
  specification_version: 4
134
134
  summary: Simple gem for JAN code