rdpl 0.1.0

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.
data/spec/rdpl_spec.rb ADDED
@@ -0,0 +1,33 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Rdpl do
4
+ describe "::STX" do
5
+ it "should have the 2 ASCII value" do
6
+ Rdpl::STX.should == 2.chr
7
+ end
8
+ end
9
+
10
+ describe "::CR" do
11
+ it "should have the 13 ASCII value" do
12
+ Rdpl::CR.should == 13.chr
13
+ end
14
+ end
15
+
16
+ describe '::LF' do
17
+ it "should have the 10 ASCII value" do
18
+ Rdpl::LF.should == 10.chr
19
+ end
20
+ end
21
+
22
+ describe "::FEED" do
23
+ it "should have the 'F' caracter" do
24
+ Rdpl::FEED.should == 'F'
25
+ end
26
+ end
27
+
28
+ describe "::NEW_LILE" do
29
+ it "should be equal to CR and LF concatenated" do
30
+ Rdpl::NEW_LINE.should == Rdpl::CR + Rdpl::LF
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,192 @@
1
+ shared_examples_for "element" do
2
+ let(:element) { described_class.new }
3
+
4
+ describe "#rotation=" do
5
+ it "defines the element's rotation" do
6
+ element.rotation = 1
7
+ element.instance_variable_get(:@rotation).should == 1
8
+ end
9
+
10
+ it "raises InvalidRotationError if the value is below the range limit" do
11
+ lambda do
12
+ element.rotation = element.send(:valid_rotation_range).to_a[0] - 1
13
+ end.should raise_error(Rdpl::Element::InvalidRotationError)
14
+ end
15
+
16
+ it "raises InvalidRotationError if the value is above the range limit" do
17
+ lambda do
18
+ element.rotation = element.send(:valid_rotation_range).to_a[-1] + 1
19
+ end.should raise_error(Rdpl::Element::InvalidRotationError)
20
+ end
21
+ end
22
+
23
+ describe "#rotation" do
24
+ it "returns the element's rotation" do
25
+ array = element.send(:valid_rotation_range).entries
26
+ rotation = array[rand(array.size)]
27
+ element.rotation = rotation
28
+ element.rotation.should == rotation
29
+ end
30
+
31
+ it "returns a default value when empty" do
32
+ default_rotation = element.send :default_rotation
33
+ element.rotation.should == default_rotation
34
+ end
35
+ end
36
+
37
+ describe "#font_id=" do
38
+ it "defines the element's font id" do
39
+ array = element.send(:valid_font_id_ranges).first.entries
40
+ font_id = array[rand(array.size)]
41
+ element.font_id = font_id
42
+ element.instance_variable_get(:@font_id).should == font_id
43
+ end
44
+
45
+ it "raises InvalidFontIdError if the font_id is below the range limit" do
46
+ lambda do
47
+ element.font_id = element.send(:valid_font_id_ranges).first.to_a[0] - 1
48
+ end.should raise_error(Rdpl::Element::InvalidFontIdError)
49
+ end
50
+
51
+ it "raises InvalidFontIdError if the font_id is above 9" do
52
+ lambda do
53
+ element.font_id = element.send(:valid_font_id_ranges).first.to_a[-1] + 1
54
+ end.should raise_error(Rdpl::Element::InvalidFontIdError)
55
+ end
56
+ end
57
+
58
+ describe "#font_id" do
59
+ it "returns the element font_id" do
60
+ array = element.send(:valid_font_id_ranges).first.entries
61
+ font_id = array[rand(array.size)]
62
+ element.font_id = font_id
63
+ element.font_id.should == font_id
64
+ end
65
+ end
66
+
67
+ describe "#width_multiplier=" do
68
+ it "defines the element's width multiplier" do
69
+ element.width_multiplier = 2
70
+ element.instance_variable_get(:@width_multiplier).should == 2
71
+ end
72
+
73
+ it "raises InvalidWidthMultiplierError if the multiplier is less than 1 (base 25)" do
74
+ lambda do
75
+ element.width_multiplier = 0
76
+ end.should raise_error(Rdpl::Element::InvalidWidthMultiplierError)
77
+ end
78
+
79
+ it "raises InvalidWidthMultiplierError if the multiplier is more than O (base 25)" do
80
+ lambda do
81
+ element.width_multiplier = 'P'
82
+ end.should raise_error(Rdpl::Element::InvalidWidthMultiplierError)
83
+ end
84
+
85
+ it "raises InvalidWidthMultiplierError if the multiplier is not in base 25" do
86
+ lambda do
87
+ element.width_multiplier = 10
88
+ end.should raise_error(Rdpl::Element::InvalidWidthMultiplierError)
89
+ end
90
+ end
91
+
92
+ describe "#width_multiplier" do
93
+ it "returns the defined width multiplier" do
94
+ element.width_multiplier = 9
95
+ element.width_multiplier.should == 9
96
+ end
97
+
98
+ it "returns 1 by default" do
99
+ element.width_multiplier.should == 1
100
+ end
101
+ end
102
+
103
+ describe "height_multiplier=" do
104
+ it "defines the element's height multiplier" do
105
+ element.height_multiplier = 2
106
+ element.instance_variable_get(:@height_multiplier).should == 2
107
+ end
108
+
109
+ it "raises InvalidHeightMultiplierError if the multiplier is less than 1 (base 25)" do
110
+ lambda do
111
+ element.height_multiplier = 0
112
+ end.should raise_error(Rdpl::Element::InvalidHeightMultiplierError)
113
+ end
114
+
115
+ it "raises InvalidHeightMultiplierError if the multiplier is more than O (base 25)" do
116
+ lambda do
117
+ element.height_multiplier = 'P'
118
+ end.should raise_error(Rdpl::Element::InvalidHeightMultiplierError)
119
+ end
120
+
121
+ it "raises InvalidHeightMultiplierError if the multiplier is not in base 25" do
122
+ lambda do
123
+ element.height_multiplier = 10
124
+ end.should raise_error(Rdpl::Element::InvalidHeightMultiplierError)
125
+ end
126
+ end
127
+
128
+ describe "#height_multiplier" do
129
+ it "returns the defined height multiplier" do
130
+ element.height_multiplier = 9
131
+ element.height_multiplier.should == 9
132
+ end
133
+
134
+ it "returns 1 by default" do
135
+ element.height_multiplier.should == 1
136
+ end
137
+ end
138
+
139
+ describe "#row_position=" do
140
+ it "defines how far above the 'home position' the element is" do
141
+ element.row_position = 10
142
+ element.instance_variable_get(:@row_position).should == 10
143
+ end
144
+ end
145
+
146
+ describe "#row_position" do
147
+ it "returns the element's row position (y)" do
148
+ element.row_position = 10
149
+ element.row_position.should == 10
150
+ end
151
+
152
+ it "returns 0 (zero) by default" do
153
+ element.row_position.should be_zero
154
+ end
155
+ end
156
+
157
+ describe "#column_position=" do
158
+ it "defines how far to the right from the 'home position' the element is" do
159
+ element.column_position = 10
160
+ element.instance_variable_get(:@column_position).should == 10
161
+ end
162
+ end
163
+
164
+ describe "#column_position" do
165
+ it "returns the element's column position (x)" do
166
+ element.column_position = 10
167
+ element.column_position.should == 10
168
+ end
169
+
170
+ it "returns 0 (zero) by default" do
171
+ element.column_position.should be_zero
172
+ end
173
+ end
174
+
175
+ describe "#data=" do
176
+ it "defines the element's data" do
177
+ element.data = 'foobar'
178
+ element.instance_variable_get(:@data).should == 'foobar'
179
+ end
180
+ end
181
+
182
+ describe "#data" do
183
+ it "returns the element's data" do
184
+ element.data = 'foobar'
185
+ element.data.should == 'foobar'
186
+ end
187
+
188
+ it "returns an empty string by default" do
189
+ element.data.should == ''
190
+ end
191
+ end
192
+ end
@@ -0,0 +1,73 @@
1
+ shared_examples_for 'lines and boxes' do
2
+ describe "#vertical_width=" do
3
+ it "defines the line's vertical width" do
4
+ element.vertical_width = 10
5
+ element.instance_variable_get(:@vertical_width).should == 10
6
+ end
7
+ end
8
+
9
+ describe "#vertical_width" do
10
+ it "returns the line's vertical width" do
11
+ element.vertical_width = 10
12
+ element.vertical_width.should == 10
13
+ end
14
+
15
+ it "returns 0 by default" do
16
+ element.vertical_width.should be_zero
17
+ end
18
+ end
19
+
20
+ describe "#horizontal_width=" do
21
+ it "defines the line's horizontal width" do
22
+ element.horizontal_width = 15
23
+ element.instance_variable_get(:@horizontal_width).should == 15
24
+ end
25
+ end
26
+
27
+ describe "#horizontal_width" do
28
+ it "returns the line's horizontal width" do
29
+ element.horizontal_width = 15
30
+ element.horizontal_width.should == 15
31
+ end
32
+
33
+ it "returns 0 by default" do
34
+ element.horizontal_width.should be_zero
35
+ end
36
+ end
37
+
38
+ describe "#width_multiplier" do
39
+ it "defaults to 1" do
40
+ element.width_multiplier.should == 1
41
+ end
42
+ end
43
+
44
+ describe "#height_multiplier" do
45
+ it "defaults to 1" do
46
+ element.height_multiplier.should == 1
47
+ end
48
+ end
49
+
50
+ describe "#width_multiplier=" do
51
+ it "should raise FixedValueError when trying to change the value" do
52
+ lambda do
53
+ element.width_multiplier = 2
54
+ end.should raise_error(Rdpl::Element::FixedValueError)
55
+ end
56
+ end
57
+
58
+ describe "#height_multiplier=" do
59
+ it "should raise FixedValueError when trying to change the value" do
60
+ lambda do
61
+ element.height_multiplier = 2
62
+ end.should raise_error(Rdpl::Element::FixedValueError)
63
+ end
64
+ end
65
+
66
+ describe "#data=" do
67
+ it "should raise InvalidAssigmentError" do
68
+ lambda do
69
+ element.data = 'foo'
70
+ end.should raise_error(Rdpl::Element::InvalidAssigmentError)
71
+ end
72
+ end
73
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format s -c
@@ -0,0 +1,11 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'rdpl'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Dir.glob(File.join(File.dirname(__FILE__), 'shared_examples/*.rb')).each {|f| require f }
8
+
9
+ Spec::Runner.configure do |config|
10
+
11
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rdpl
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - "C\xC3\xA1ssio Marques"
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-09-21 00:00:00 -03:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 27
30
+ segments:
31
+ - 1
32
+ - 3
33
+ - 0
34
+ version: 1.3.0
35
+ type: :development
36
+ version_requirements: *id001
37
+ description: "RDPL provides a way to create labels for the Datamax\xE2\x84\xA2 printers using plain Ruby, through an abstraction of the DPL (Datamax Programming Language)"
38
+ email: cassiommc@gmail.com
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files:
44
+ - LICENSE
45
+ - README.rdoc
46
+ files:
47
+ - .document
48
+ - .gitignore
49
+ - .rvmrc
50
+ - LICENSE
51
+ - README.rdoc
52
+ - Rakefile
53
+ - VERSION
54
+ - lib/elements/barcode.rb
55
+ - lib/elements/bitmapped_text.rb
56
+ - lib/elements/box.rb
57
+ - lib/elements/element.rb
58
+ - lib/elements/graphic.rb
59
+ - lib/elements/line.rb
60
+ - lib/elements/lines_and_boxes.rb
61
+ - lib/job.rb
62
+ - lib/label.rb
63
+ - lib/rdpl.rb
64
+ - spec/elements/barcode_spec.rb
65
+ - spec/elements/bitmapped_text_spec.rb
66
+ - spec/elements/box_spec.rb
67
+ - spec/elements/line_spec.rb
68
+ - spec/job_spec.rb
69
+ - spec/label_spec.rb
70
+ - spec/rdpl_spec.rb
71
+ - spec/shared_examples/element.rb
72
+ - spec/shared_examples/lines_and_boxes.rb
73
+ - spec/spec.opts
74
+ - spec/spec_helper.rb
75
+ has_rdoc: true
76
+ homepage: http://github.com/cassiomarques/rdpl
77
+ licenses: []
78
+
79
+ post_install_message:
80
+ rdoc_options:
81
+ - --charset=UTF-8
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ hash: 3
90
+ segments:
91
+ - 0
92
+ version: "0"
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ hash: 3
99
+ segments:
100
+ - 0
101
+ version: "0"
102
+ requirements: []
103
+
104
+ rubyforge_project:
105
+ rubygems_version: 1.3.7
106
+ signing_key:
107
+ specification_version: 3
108
+ summary: "Create Datamax\xE2\x84\xA2 labels using Ruby!"
109
+ test_files:
110
+ - spec/elements/barcode_spec.rb
111
+ - spec/elements/bitmapped_text_spec.rb
112
+ - spec/elements/box_spec.rb
113
+ - spec/elements/line_spec.rb
114
+ - spec/job_spec.rb
115
+ - spec/label_spec.rb
116
+ - spec/rdpl_spec.rb
117
+ - spec/shared_examples/element.rb
118
+ - spec/shared_examples/lines_and_boxes.rb
119
+ - spec/spec_helper.rb