laser-cutter 0.4.0 → 0.4.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: df5fc0b8025663e5d008e970a56fa3fe49f5a275
4
- data.tar.gz: c9a4201c05edf34506255706906d979249047b92
3
+ metadata.gz: 5a4b3007500f32bdfa746101e673e39f1926dbff
4
+ data.tar.gz: c78f838314670acc0dbe0a938a30ce558e625539
5
5
  SHA512:
6
- metadata.gz: 88b3fbacb5fbc6f0049f7799a7721f9b22ccff4ddfe313496a051b931ce5b9184efd273b68981234038f3d5967e1b073d0d8bbe6aa88a35a925bd4f2ab7b343f
7
- data.tar.gz: 4c816f055a6f32109305ece7f3b7e2cb98d69d71b70d2e8cc6f7c566edd475c3cb6cb8a53de4a1598187f0b88ba170026acecd1a09329b0d8f0f4567e2581c08
6
+ metadata.gz: cdfc3dae22670701459a011656d8f3e6b2b3afd70958de0caf132067f85d4b01159fefe32974e7a694143d55b321519f2514cdb6d8b7d76742bcd7f5df8430a6
7
+ data.tar.gz: ba642a3dcfb26df3626e153ce003452fe2d5e91a94ffa01074c6cf276a9fe8169104a981a993d5fd622096358a0184bc78f54a7e5a2b052df6b3359a46546590
data/.rspec CHANGED
@@ -1,2 +1,3 @@
1
1
  --color
2
2
  --format progress
3
+ --require rspec/legacy_formatters
@@ -25,5 +25,6 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency 'bundler', "~> 1.6"
26
26
  spec.add_development_dependency 'rake'
27
27
  spec.add_development_dependency 'rspec'
28
+ spec.add_development_dependency 'rspec-legacy_formatters'
28
29
 
29
30
  end
@@ -28,16 +28,20 @@ module Laser
28
28
 
29
29
  SIZE_REGEXP = /[\d\.]+x[\d\.]+x[\d\.]+\/[\d\.]+\/[\d\.]+/
30
30
 
31
- FLOATS = %w(width height depth thickness notch margin padding stroke)
31
+ FLOATS = %w(width height depth thickness notch margin padding stroke)
32
+ NON_ZERO = %w(width height depth thickness stroke)
32
33
  REQUIRED = %w(width height depth thickness notch file)
33
34
 
34
35
  def initialize(options = {})
35
- options.delete_if{|k,v| v.nil?}
36
+ options.delete_if { |k, v| v.nil? }
37
+ if options['units'] && !UNIT_SPECIFIC_DEFAULTS.keys.include?(options['units'])
38
+ options.delete('units')
39
+ end
36
40
  self.merge!(DEFAULTS)
37
41
  self.merge!(options)
38
42
  if self['size'] && self['size'] =~ SIZE_REGEXP
39
43
  dim, self['thickness'], self['notch'] = self['size'].split('/')
40
- self['width'],self['height'],self['depth'] = dim.split('x')
44
+ self['width'], self['height'], self['depth'] = dim.split('x')
41
45
  delete('size')
42
46
  end
43
47
  FLOATS.each do |k|
@@ -54,21 +58,43 @@ module Laser
54
58
  unless missing.empty?
55
59
  raise MissingOption.new("#{missing.join(', ')} #{missing.size > 1 ? 'are' : 'is'} required, but missing.")
56
60
  end
61
+
62
+ NON_ZERO.each do |k|
63
+ if self[k] == 0
64
+ raise MissingOption.new("#{missing.join(', ')} #{missing.size > 1 ? 'are' : 'is'} required, but is zero.")
65
+ end
66
+ end
57
67
  end
58
68
 
59
- def all_page_sizes
69
+ def page_size_values
60
70
  unit = 1.0 / 72.0 # PDF units per inch
61
71
  multiplier = (self.units == 'in') ? 1.0 : 25.4
62
72
  h = PDF::Core::PageGeometry::SIZES
63
- output = "\n"
73
+ array = []
64
74
  h.keys.sort.each do |k|
65
- output << sprintf("\t%10s:\t%6.1f x %6.1f\n",
66
- k,
67
- multiplier * h[k][0].to_f * unit,
68
- multiplier * h[k][1].to_f * unit )
75
+ array << [ k,
76
+ multiplier * h[k][0].to_f * unit,
77
+ multiplier * h[k][1].to_f * unit ]
78
+ end
79
+ array
80
+ end
81
+
82
+ def all_page_sizes
83
+ output = ""
84
+ page_size_values.each do |k|
85
+ output << sprintf("\t%10s:\t%6.1f x %6.1f\n", *k)
69
86
  end
70
87
  output
71
88
  end
89
+
90
+ def change_units(new_units)
91
+ return if (self.units.eql?(new_units) || !UNIT_SPECIFIC_DEFAULTS.keys.include?(new_units))
92
+ k = (self.units == 'in') ? 25.4 : 0.039370079
93
+ FLOATS.each do |field|
94
+ self.send("#{field}=".to_sym, self.send(field.to_sym) * k)
95
+ end
96
+ self.units = new_units
97
+ end
72
98
  end
73
99
  end
74
100
  end
@@ -11,7 +11,7 @@ module Laser
11
11
  end
12
12
 
13
13
  def render pdf = nil
14
- pdf = Prawn::Document.new(:margin => options.margin.send(options.units),
14
+ pdf = Prawn::Document.new(:margin => options.margin.to_f.send(options.units.to_sym),
15
15
  :page_size => options.page_size,
16
16
  :page_layout => options.page_layout.to_sym)
17
17
  header = <<-EOF
@@ -1,5 +1,5 @@
1
1
  module Laser
2
2
  module Cutter
3
- VERSION = "0.4.0"
3
+ VERSION = "0.4.1"
4
4
  end
5
5
  end
@@ -37,7 +37,40 @@ module Laser
37
37
  end
38
38
  end
39
39
  end
40
+ end
41
+
42
+ context "#default to mm for incorrect units" do
43
+ let(:opts) { {"size" => "2x3x2/0.125/0.5", "units" => 'xx'} }
44
+ it 'should default to millimeters' do
45
+ expect(config.units).to eql('mm')
46
+ end
47
+ end
40
48
 
49
+ context "#change_units" do
50
+ context "from inches" do
51
+ let(:opts) { {"size" => "2.0x3x2/0.125/0.5", 'padding' => '4.0', "units" => 'in'} }
52
+ it "should convert to mm" do
53
+ expect(config.width).to eql(2.0)
54
+ config.change_units('in')
55
+ expect(config.width).to eql(2.0)
56
+ config.change_units('mm')
57
+ expect(config.width).to eql(50.8)
58
+ expect(config.padding).to eql(101.6)
59
+ expect(config.units).to eql('mm')
60
+ end
61
+ end
62
+ context "from mm" do
63
+ let(:opts) { {"size" => "20.0x30.0x40.0/5/5", 'margin' => '10.0', "units" => 'mm'} }
64
+ it "should convert to inches" do
65
+ expect(config.width).to eql(20.0)
66
+ config.change_units('mm')
67
+ expect(config.width).to eql(20.0)
68
+ config.change_units('in')
69
+ expect(config.width).to be_within(0.001).of(0.787401575)
70
+ expect(config.margin).to be_within(0.001).of(0.393700787)
71
+ expect(config.units).to eql('in')
72
+ end
73
+ end
41
74
  end
42
75
  end
43
76
  end
@@ -19,7 +19,7 @@ require "codeclimate-test-reporter"
19
19
 
20
20
 
21
21
  RSpec.configure do |config|
22
- config.treat_symbols_as_metadata_keys_with_true_values = true
22
+ #config.treat_symbols_as_metadata_keys_with_true_values = true
23
23
  config.run_all_when_everything_filtered = true
24
24
  config.filter_run :focus
25
25
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: laser-cutter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Konstantin Gredeskoul
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-23 00:00:00.000000000 Z
11
+ date: 2014-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: prawn
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec-legacy_formatters
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  description: Similar to the older BoxMaker, this ruby gem generates PDFs that can
98
112
  be used as a basis for cutting boxes on a typical laser cutter. The intention was
99
113
  to create an extensible, well tested, and modern ruby gem for generating PDF templates