dot_grid 0.0.4 → 0.0.5

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: 54a925c03705950b5f01d2c6cb92ee1bc9f3e023
4
- data.tar.gz: 4511d7eea919e7397faa5a181a94bd8b20aea0c9
3
+ metadata.gz: 7ffb5b75ffa638ae3bfd9d7b42ca6ef7c6bc92a9
4
+ data.tar.gz: e5849864c9d5bb7671909055a2b352d63bfb915d
5
5
  SHA512:
6
- metadata.gz: 8c4cb6d4f14c07903142d916f181fe23fefb120b988fbc1923223d1b73407bfecc479b034b7e42137ebf0fb88055c97db31698e5b431dbf03b336b64d6789a06
7
- data.tar.gz: ab5e6792388c751dbf3b0e463d613689b8bcffd42b4a340ce0f818cd3b871165a4837375a2b6f9ea2a9a2122d79cc5ecc84615e44a181fef092bd2d84198ff28
6
+ metadata.gz: c362a59e770ac32c855d1c3ba63937c42dcab3bdb132705fa134ccb813cdf760d1fb8b0ccb681f6ea85db6f134867dada43c5ff96ff4d12b71d7aaaeb9d06222
7
+ data.tar.gz: 2a8006d84e41212fc53045952e0ffb4da63850a576c3664f7448e478a9c4c3a5f3181fb27c26c6ee754f6709c47ab2c256986faba95cb0bef471d1b4ceb5066d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dot_grid (0.0.3)
4
+ dot_grid (0.0.5)
5
5
  prawn (~> 1.0.0)
6
6
  require_all (~> 1.3.2)
7
7
  trollop (~> 2.0)
@@ -0,0 +1,15 @@
1
+ module DotGrid
2
+ class BoundingBox
3
+ attr_accessor(
4
+ :upper_left,
5
+ :width,
6
+ :height
7
+ )
8
+
9
+ def initialize(params)
10
+ @upper_left = params[:upper_left]
11
+ @width = params[:width]
12
+ @height = params[:height]
13
+ end
14
+ end
15
+ end
@@ -1,18 +1,9 @@
1
1
  module DotGrid
2
2
  module Page
3
3
  class Checkerboard < Page
4
- attr_accessor(
5
- :pattern,
6
- )
7
4
 
8
- def initialize(params)
9
- super
10
- @pattern = ::DotGrid::Pattern::Checkerboard.new(params.merge!(:bounds => pdf.bounds))
11
- end
12
-
13
- def generate
14
- super
15
- pattern.draw
5
+ def post_initialize(params)
6
+ add_pattern(::DotGrid::Pattern::Checkerboard.new(params))
16
7
  end
17
8
  end
18
9
  end
@@ -1,21 +1,9 @@
1
1
  module DotGrid
2
2
  module Page
3
3
  class DotGrid < Page
4
- attr_accessor(
5
- :dot_weight,
6
- :grid_color,
7
- :spacing,
8
- :pattern
9
- )
10
4
 
11
- def initialize(params)
12
- super
13
- @pattern = ::DotGrid::Pattern::DotGrid.new(params.merge!(:bounds => pdf.bounds))
14
- end
15
-
16
- def generate
17
- super
18
- pattern.draw
5
+ def post_initialize(params)
6
+ add_pattern(::DotGrid::Pattern::DotGrid.new(params))
19
7
  end
20
8
  end
21
9
  end
@@ -1,20 +1,9 @@
1
1
  module DotGrid
2
2
  module Page
3
3
  class Grid < Page
4
- attr_accessor(
5
- :grid_color,
6
- :spacing,
7
- :pattern
8
- )
9
4
 
10
- def initialize(params)
11
- super
12
- @pattern = ::DotGrid::Pattern::Grid.new(params.merge!(:bounds => pdf.bounds))
13
- end
14
-
15
- def generate
16
- super
17
- pattern.draw
5
+ def post_initialize(params)
6
+ add_pattern(::DotGrid::Pattern::Grid.new(params))
18
7
  end
19
8
  end
20
9
  end
@@ -1,20 +1,10 @@
1
1
  module DotGrid
2
2
  module Page
3
3
  class HorizontalRule < Page
4
- attr_accessor(
5
- :pattern
6
- )
7
4
 
8
- def initialize(params)
9
- super
10
- @pattern = ::DotGrid::Pattern::HorizontalRule.new(params.merge!(:bounds => pdf.bounds))
11
- end
12
-
13
- def generate
14
- super
15
- pattern.draw
5
+ def post_initialize(params)
6
+ add_pattern(::DotGrid::Pattern::HorizontalRule.new(params))
16
7
  end
17
8
  end
18
9
  end
19
10
  end
20
-
@@ -3,37 +3,26 @@ module DotGrid
3
3
  class Page
4
4
  attr_accessor(
5
5
  :pdf,
6
- :dot_weight,
7
- :grid_color,
8
- :spacing
6
+ :patterns
9
7
  )
10
8
 
11
9
  def initialize(params)
12
10
  @pdf = params[:pdf]
13
- @dot_weight = params[:dot_weight] || 1.5
14
- @grid_color = params[:grid_color] || "B3B3B3"
15
- @spacing = params[:spacing] ? params[:spacing].mm : 5.mm
11
+ @patterns = []
12
+ post_initialize(params)
16
13
  end
17
14
 
18
- def generate
19
- pdf.start_new_page
20
- end
21
-
22
- def page_width
23
- pdf.bounds.width
15
+ def post_initialize(params)
16
+ nil
24
17
  end
25
18
 
26
- def page_height
27
- pdf.bounds.height
19
+ def add_pattern(pattern)
20
+ patterns << pattern
28
21
  end
29
22
 
30
- def draw_dot_grid(rows, columns, left_start, height_start)
31
- pdf.fill_color grid_color
32
- (1..rows).each do |row|
33
- (1..columns).each do |col|
34
- pdf.fill_circle [left_start + (col-1)*spacing, height_start - spacing - (row-1)*spacing], dot_weight
35
- end
36
- end
23
+ def generate
24
+ pdf.start_new_page
25
+ patterns.each { |pattern| pattern.draw }
37
26
  end
38
27
  end
39
28
  end
@@ -3,29 +3,46 @@ module DotGrid
3
3
  class Planner < Page
4
4
  attr_accessor(
5
5
  :planner_color_1,
6
- :planner_color_2
6
+ :planner_color_2,
7
+ :dot_weight,
8
+ :grid_color,
9
+ :spacing,
7
10
  )
8
11
 
9
12
  HEADER_HEIGHT = 0.05 # 5.0 %
10
13
  HEADER_LEFT_START = 0.05 # 5.0%
11
- SQUARE_GRID_WIDTH = 0.30 # 30.0%
14
+ SQUARE_GRID_WIDTH = 0.32 # 32.0% - Basically, what looks good on 8.5 x 11
12
15
  HEADER_GAP_WIDTH = 0.03 # 3.0%
13
- DOT_GRID_COLUMN_WIDTH = 0.62 # 62%
14
- SQUARE_GRID_ROWS_WIDTH = 0.80 # 80%
15
16
  FOOT_HEIGHT_RATIO = 2 # Ratio of footer to header
16
17
 
17
- def initialize(params)
18
- super
18
+ def post_initialize(params)
19
19
  @planner_color_1 = params[:planner_color_1] || "CCCCCC"
20
20
  @planner_color_2 = params[:planner_color_2] || "0099ff"
21
+ @dot_weight = params[:dot_weight] || 1.5
22
+ @grid_color = params[:grid_color] || "B3B3B3"
23
+ @spacing = params[:spacing] ? params[:spacing].mm : 5.mm
24
+ add_pattern(::DotGrid::Pattern::SquareGrid.new(params.merge!(:bounds => square_grid_bounds, grid_color: @planner_color_1)))
25
+ add_pattern(::DotGrid::Pattern::DotGrid.new(params.merge!(:bounds => dot_grid_bounds)))
26
+ end
27
+
28
+ def square_grid_bounds
29
+ ::DotGrid::BoundingBox.new(upper_left: [header_left_start, grid_top], width: header_left_width, height: grid_height)
30
+ end
31
+
32
+ def dot_grid_bounds
33
+ ::DotGrid::BoundingBox.new(upper_left: [header_right_start, grid_top], width: header_right_width, height: grid_height)
21
34
  end
22
35
 
23
36
  def header_height
24
37
  HEADER_HEIGHT * page_height
25
38
  end
26
39
 
27
- def square_grid_columns
28
- ((SQUARE_GRID_WIDTH * page_width) / spacing).floor
40
+ def grid_top
41
+ page_height - header_height - spacing
42
+ end
43
+
44
+ def grid_height
45
+ (grid_top - footer_height - spacing)
29
46
  end
30
47
 
31
48
  def header_left_color
@@ -37,7 +54,7 @@ module DotGrid
37
54
  end
38
55
 
39
56
  def header_left_width
40
- square_grid_columns*spacing
57
+ ((SQUARE_GRID_WIDTH * page_width) / spacing).floor * spacing
41
58
  end
42
59
 
43
60
  def header_gap_start
@@ -48,14 +65,6 @@ module DotGrid
48
65
  page_width * HEADER_GAP_WIDTH
49
66
  end
50
67
 
51
- def dot_grid_columns
52
- (page_width * DOT_GRID_COLUMN_WIDTH / spacing).floor + 2
53
- end
54
-
55
- def dot_grid_rows
56
- square_grid_rows + 1
57
- end
58
-
59
68
  def header_right_color
60
69
  planner_color_2
61
70
  end
@@ -68,10 +77,6 @@ module DotGrid
68
77
  page_width - header_right_start
69
78
  end
70
79
 
71
- def square_grid_rows
72
- (page_height * SQUARE_GRID_ROWS_WIDTH / spacing).floor
73
- end
74
-
75
80
  def footer_height
76
81
  header_height * FOOT_HEIGHT_RATIO
77
82
  end
@@ -85,12 +90,6 @@ module DotGrid
85
90
  # Header right
86
91
  draw_header(header_right_start, header_right_width, header_height, header_right_color)
87
92
 
88
- # Square Grid Left
89
- draw_square_grid_left(square_grid_rows, square_grid_columns, header_left_color, header_left_start, page_height - header_height - spacing, spacing)
90
-
91
- # Dot Grid Right
92
- draw_dot_grid(dot_grid_rows, dot_grid_columns, header_right_start, page_height-header_height)
93
-
94
93
  # Footer
95
94
  draw_footer(planner_color_1, header_left_start, footer_height, page_width-header_left_start)
96
95
  end
@@ -100,19 +99,18 @@ module DotGrid
100
99
  pdf.fill_rectangle [header_start, page_height], header_width, header_height
101
100
  end
102
101
 
103
- def draw_square_grid_left(square_grid_rows, square_grid_columns, grid_color, left_start, height_start, spacing)
104
- pdf.fill_color grid_color
105
- (1..square_grid_rows).each do |row|
106
- (1..square_grid_columns).each do |col|
107
- pdf.fill_rectangle [left_start + (col-1)*spacing, height_start - (row-1)*spacing], spacing-1 ,spacing-1
108
- end
109
- end
110
- end
111
-
112
102
  def draw_footer(footer_color, footer_start, footer_height, footer_width)
113
103
  pdf.fill_color footer_color
114
104
  pdf.fill_rectangle [footer_start, footer_height], footer_width, footer_height
115
105
  end
106
+
107
+ def page_width
108
+ pdf.bounds.width
109
+ end
110
+
111
+ def page_height
112
+ pdf.bounds.height
113
+ end
116
114
  end
117
115
  end
118
116
  end
@@ -2,14 +2,14 @@ module DotGrid
2
2
  module Pattern
3
3
  class Checkerboard < Pattern
4
4
 
5
+ def draw_square?(row, column)
6
+ (row % 2 == 0 && column % 2 == 0) || (row % 2 == 1 && column % 2 == 1)
7
+ end
8
+
5
9
  def draw
6
10
  pdf.fill_color grid_color
7
- (0..rows).each do |row|
8
- (0..columns).each do |column|
9
- if (row % 2 == 0 && column % 2 == 0) || (row % 2 == 1 && column % 2 == 1)
10
- pdf.fill_rectangle [column*spacing, row*spacing], spacing, spacing
11
- end
12
- end
11
+ draw_grid do |row, column|
12
+ pdf.fill_rectangle [column*spacing, row*spacing], spacing, spacing if draw_square?(row, column)
13
13
  end
14
14
  end
15
15
  end
@@ -11,10 +11,8 @@ module DotGrid
11
11
 
12
12
  def draw
13
13
  pdf.fill_color grid_color
14
- (0..rows).each do |row|
15
- (0..columns).each do |col|
16
- pdf.fill_circle [col*spacing, row*spacing], dot_weight
17
- end
14
+ draw_grid do |row, column|
15
+ pdf.fill_circle [column*spacing, row*spacing], dot_weight
18
16
  end
19
17
  end
20
18
  end
@@ -3,11 +3,9 @@ module DotGrid
3
3
  class Grid < Pattern
4
4
  def draw
5
5
  pdf.stroke_color grid_color
6
- (0..rows).each do |row|
7
- pdf.stroke_horizontal_line(0, bounds.width, :at => row*spacing)
8
- end
9
- (0..columns).each do |column|
10
- pdf.stroke_vertical_line(0, bounds.height, :at => column*spacing)
6
+ draw_grid do |row, column|
7
+ pdf.stroke_horizontal_line(0, bounds.width, :at => row*spacing) if column == 0
8
+ pdf.stroke_vertical_line(0, bounds.height, :at => column*spacing) if row == 0
11
9
  end
12
10
  end
13
11
  end
@@ -1,11 +1,10 @@
1
1
  module DotGrid
2
2
  module Pattern
3
3
  class HorizontalRule < Pattern
4
-
5
4
  def draw
6
5
  pdf.stroke_color grid_color
7
- (0..rows).each do |row|
8
- pdf.stroke_horizontal_line(0, bounds.width, :at => row*spacing)
6
+ draw_grid do |row, column|
7
+ pdf.stroke_horizontal_line(0, bounds.width, :at => row*spacing) if column == 0
9
8
  end
10
9
  end
11
10
  end
@@ -10,7 +10,7 @@ module DotGrid
10
10
 
11
11
  def initialize(params = {})
12
12
  @pdf = params[:pdf]
13
- @bounds = params[:bounds]
13
+ @bounds = params[:bounds] || ::DotGrid::BoundingBox.new(upper_left: [0, pdf.bounds.height], width: pdf.bounds.width, height: pdf.bounds.height)
14
14
  @grid_color = params[:grid_color] || "B3B3B3"
15
15
  @spacing = params[:spacing] ? params[:spacing].mm : 5.mm
16
16
  post_initialize(params)
@@ -28,6 +28,16 @@ module DotGrid
28
28
  (bounds.width / spacing).floor
29
29
  end
30
30
 
31
+ def draw_grid(shorten = false)
32
+ pdf.bounding_box(bounds.upper_left, width: bounds.width, height: bounds.height) do
33
+ (0..(shorten ? rows-1 : rows)).each do |row|
34
+ (0..(shorten ? columns-1 : columns)).each do |column|
35
+ yield row, column
36
+ end
37
+ end
38
+ end
39
+ end
40
+
31
41
  def draw
32
42
  raise NotImplementedError
33
43
  end
@@ -0,0 +1,12 @@
1
+ module DotGrid
2
+ module Pattern
3
+ class SquareGrid < Pattern
4
+ def draw
5
+ pdf.fill_color grid_color
6
+ draw_grid(true) do |row, column|
7
+ pdf.fill_rectangle [column*spacing, (row+1)*spacing], spacing-1, spacing-1
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module DotGrid
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/dot_grid.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'dot_grid/generator'
2
+ require 'dot_grid/bounding_box'
2
3
 
3
4
  require 'dot_grid/page/page'
4
5
  require 'dot_grid/page/dot_grid'
@@ -12,6 +13,7 @@ require 'dot_grid/pattern/grid'
12
13
  require 'dot_grid/pattern/dot_grid'
13
14
  require 'dot_grid/pattern/checkerboard'
14
15
  require 'dot_grid/pattern/horizontal_rule'
16
+ require 'dot_grid/pattern/square_grid'
15
17
 
16
18
  module DotGrid
17
19
  end
@@ -1,19 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "DotGrid::Page::Checkerboard" do
4
- describe "#draw" do
5
- let(:pdf) { double('pdf', bounds: double('bounds')) }
6
- let(:subject) { DotGrid::Page::Checkerboard.new({pdf: pdf})}
7
- let(:pattern) { double('pattern') }
4
+ describe "#post_initialize" do
5
+ let(:subject) { DotGrid::Page::Checkerboard.new({})}
8
6
 
9
7
  before do
10
- allow(pdf).to receive(:start_new_page)
11
- allow(subject).to receive(:pattern).and_return(pattern)
8
+ allow(::DotGrid::Pattern::Checkerboard).to receive(:new)
12
9
  end
13
10
 
14
- it "draws the pattern" do
15
- expect(pattern).to receive(:draw)
16
- subject.generate
11
+ it "adds the pattern" do
12
+ expect(subject).to receive(:add_pattern)
13
+ subject.post_initialize({})
17
14
  end
18
15
  end
19
16
  end
@@ -1,28 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "DotGrid::Page::DotGrid" do
4
- describe "#initialize" do
5
- let(:pdf) { double('pdf', bounds: double('bounds')) }
6
-
7
- it "creates a dot grid pattern" do
8
- expect(::DotGrid::Pattern::DotGrid).to receive(:new)
9
- DotGrid::Page::DotGrid.new({pdf: pdf})
10
- end
11
- end
12
-
13
- describe "#generate" do
14
- let(:pdf) { double('pdf', bounds: double('bounds')) }
15
- let(:subject) { DotGrid::Page::DotGrid.new({pdf: pdf})}
16
- let(:pattern) { double('pattern') }
4
+ describe "#post_initialize" do
5
+ let(:subject) { DotGrid::Page::DotGrid.new({})}
17
6
 
18
7
  before do
19
- allow(pdf).to receive(:start_new_page)
20
- allow(subject).to receive(:pattern).and_return(pattern)
8
+ allow(::DotGrid::Pattern::DotGrid).to receive(:new)
21
9
  end
22
10
 
23
- it "draws the pattern" do
24
- expect(pattern).to receive(:draw)
25
- subject.generate
11
+ it "adds the pattern" do
12
+ expect(subject).to receive(:add_pattern)
13
+ subject.post_initialize({})
26
14
  end
27
15
  end
28
16
  end
@@ -1,28 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "DotGrid::Page::Grid" do
4
- describe "#initialize" do
5
- let(:pdf) { double('pdf', bounds: double('bounds')) }
6
-
7
- it "creates a dot grid pattern" do
8
- expect(::DotGrid::Pattern::Grid).to receive(:new)
9
- DotGrid::Page::Grid.new({pdf: pdf})
10
- end
11
- end
12
-
13
- describe "#generate" do
14
- let(:pdf) { double('pdf', bounds: double('bounds')) }
15
- let(:subject) { DotGrid::Page::Grid.new({pdf: pdf})}
16
- let(:pattern) { double('pattern') }
4
+ describe "#post_initialize" do
5
+ let(:subject) { DotGrid::Page::Grid.new({})}
17
6
 
18
7
  before do
19
- allow(pdf).to receive(:start_new_page)
20
- allow(subject).to receive(:pattern).and_return(pattern)
8
+ allow(::DotGrid::Pattern::Grid).to receive(:new)
21
9
  end
22
10
 
23
11
  it "draws the pattern" do
24
- expect(pattern).to receive(:draw)
25
- subject.generate
12
+ expect(subject).to receive(:add_pattern)
13
+ subject.post_initialize({})
26
14
  end
27
15
  end
28
16
  end
@@ -1,28 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "DotGrid::Page::HorizontalRule" do
4
- describe "#initialize" do
5
- let(:pdf) { double('pdf', bounds: double('bounds')) }
6
-
7
- it "creates a dot grid pattern" do
8
- expect(::DotGrid::Pattern::HorizontalRule).to receive(:new)
9
- DotGrid::Page::HorizontalRule.new({pdf: pdf})
10
- end
11
- end
12
-
13
- describe "#generate" do
14
- let(:pdf) { double('pdf', bounds: double('bounds')) }
15
- let(:subject) { DotGrid::Page::HorizontalRule.new({pdf: pdf})}
16
- let(:pattern) { double('pattern') }
4
+ describe "#post_initialize" do
5
+ let(:subject) { DotGrid::Page::HorizontalRule.new({})}
17
6
 
18
7
  before do
19
- allow(pdf).to receive(:start_new_page)
20
- allow(subject).to receive(:pattern).and_return(pattern)
8
+ allow(::DotGrid::Pattern::HorizontalRule).to receive(:new)
21
9
  end
22
10
 
23
11
  it "draws the pattern" do
24
- expect(pattern).to receive(:draw)
25
- subject.generate
12
+ expect(subject).to receive(:add_pattern)
13
+ subject.post_initialize({})
26
14
  end
27
15
  end
28
16
  end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe "DotGrid::Page::Page" do
4
+ describe "#initialize" do
5
+ let(:subject) { DotGrid::Page::Page.new({}) }
6
+ it "creates then empty patterns" do
7
+ expect(subject.patterns).to eq([])
8
+ end
9
+
10
+ it "calls the post initialize method" do
11
+ expect_any_instance_of(DotGrid::Page::Page).to receive(:post_initialize)
12
+ DotGrid::Page::Page.new({})
13
+ end
14
+ end
15
+
16
+ describe "#add_pattern" do
17
+ let(:subject) { DotGrid::Page::Page.new({})}
18
+ let(:pattern) { double('pattern') }
19
+
20
+ it "adds a pattern to patterns" do
21
+ expect(subject.patterns).to receive(:<<).with(pattern)
22
+ subject.add_pattern(pattern)
23
+ end
24
+ end
25
+
26
+ describe "#generate" do
27
+ let(:pdf) { double('pdf', bounds: double('bounds')) }
28
+ let(:subject) { DotGrid::Page::Page.new({pdf: pdf})}
29
+ let(:pattern) { double('pattern') }
30
+
31
+ before do
32
+ allow(pdf).to receive(:start_new_page)
33
+ allow(subject).to receive(:patterns).and_return([pattern])
34
+ allow(pattern).to receive(:draw)
35
+ end
36
+
37
+ it "starts a new page" do
38
+ expect(pdf).to receive(:start_new_page)
39
+ subject.generate
40
+ end
41
+
42
+ it "draws the pattern" do
43
+ expect(pattern).to receive(:draw)
44
+ subject.generate
45
+ end
46
+ end
47
+ end
48
+
@@ -2,7 +2,13 @@ require 'spec_helper'
2
2
 
3
3
  describe "DotGrid::Page::Planner" do
4
4
  describe "#initialize" do
5
- let(:subject) { DotGrid::Page::Planner.new({}) }
5
+ let(:pdf) { double('pdf') }
6
+ let(:bounds) { double('bounds', width: 10, height: 20) }
7
+ let(:subject) { DotGrid::Page::Planner.new({pdf: pdf}) }
8
+
9
+ before do
10
+ allow(pdf).to receive(:bounds).and_return(bounds)
11
+ end
6
12
 
7
13
  it "has a default planner color 1" do
8
14
  expect(subject.planner_color_1).to eq("CCCCCC")
@@ -15,17 +21,12 @@ describe "DotGrid::Page::Planner" do
15
21
 
16
22
  describe "#header_height" do
17
23
  let(:pdf) { double('pdf') }
24
+ let(:bounds) { double('bounds', width: 10, height: 20) }
18
25
  let(:subject) { DotGrid::Page::Planner.new({:pdf => pdf }) }
19
26
 
20
- it "returns the HEADER_HEIGHT of the header height" do
21
- allow(subject).to receive(:page_height).and_return(20)
22
- expect(subject.header_height).to eq(DotGrid::Page::Planner::HEADER_HEIGHT * subject.page_height)
27
+ before do
28
+ allow(pdf).to receive(:bounds).and_return(bounds)
23
29
  end
24
- end
25
-
26
- describe "#header_height" do
27
- let(:pdf) { double('pdf') }
28
- let(:subject) { DotGrid::Page::Planner.new({:pdf => pdf }) }
29
30
 
30
31
  it "returns the HEADER_HEIGHT of the header height" do
31
32
  allow(subject).to receive(:page_height).and_return(20)
@@ -33,28 +34,29 @@ describe "DotGrid::Page::Planner" do
33
34
  end
34
35
  end
35
36
 
36
- describe "#square_grid_columns" do
37
+ describe "#header_left_color" do
38
+ let(:bounds) { double('bounds', width: 10, height: 20) }
37
39
  let(:pdf) { double('pdf') }
38
- let(:subject) { DotGrid::Page::Planner.new({:pdf => pdf, spacing: 5 }) }
40
+ let(:subject) { DotGrid::Page::Planner.new({:pdf => pdf, planner_color_1: "DDEEFF" }) }
39
41
 
40
- it "returns the HEADER_HEIGHT of the header height" do
41
- allow(subject).to receive(:page_width).and_return(100)
42
- expect(subject.square_grid_columns).to eq((DotGrid::Page::Planner::SQUARE_GRID_WIDTH * subject.page_width / subject.spacing).floor)
42
+ before do
43
+ allow(pdf).to receive(:bounds).and_return(bounds)
43
44
  end
44
- end
45
45
 
46
- describe "#header_left_color" do
47
- let(:pdf) { double('pdf') }
48
- let(:subject) { DotGrid::Page::Planner.new({:pdf => pdf, planner_color_1: "DDEEFF" }) }
49
46
  it "returns the planner color 1" do
50
47
  expect(subject.header_left_color).to eq("DDEEFF")
51
48
  end
52
49
  end
53
50
 
54
51
  describe "#header_left_start" do
52
+ let(:bounds) { double('bounds', width: 10, height: 20) }
55
53
  let(:pdf) { double('pdf') }
56
54
  let(:subject) { DotGrid::Page::Planner.new({:pdf => pdf }) }
57
55
 
56
+ before do
57
+ allow(pdf).to receive(:bounds).and_return(bounds)
58
+ end
59
+
58
60
  it "returns the the header left_start" do
59
61
  allow(subject).to receive(:page_width).and_return(30)
60
62
  expect(subject.header_left_start).to eq(DotGrid::Page::Planner::HEADER_LEFT_START * subject.page_width)
@@ -62,9 +64,14 @@ describe "DotGrid::Page::Planner" do
62
64
  end
63
65
 
64
66
  describe "#header_gap_width" do
67
+ let(:bounds) { double('bounds', width: 10, height: 20) }
65
68
  let(:pdf) { double('pdf') }
66
69
  let(:subject) { DotGrid::Page::Planner.new({:pdf => pdf }) }
67
70
 
71
+ before do
72
+ allow(pdf).to receive(:bounds).and_return(bounds)
73
+ end
74
+
68
75
  it "returns the the header gap width" do
69
76
  allow(subject).to receive(:page_width).and_return(30)
70
77
  expect(subject.header_gap_width).to eq(DotGrid::Page::Planner::HEADER_GAP_WIDTH * subject.page_width)
@@ -72,29 +79,29 @@ describe "DotGrid::Page::Planner" do
72
79
  end
73
80
 
74
81
  describe "#header_right_color" do
82
+ let(:bounds) { double('bounds', width: 10, height: 20) }
75
83
  let(:pdf) { double('pdf') }
76
84
  let(:subject) { DotGrid::Page::Planner.new({:pdf => pdf, planner_color_2: "FFEEDD" }) }
77
- it "returns the planner color 1" do
78
- expect(subject.header_right_color).to eq("FFEEDD")
79
- end
80
- end
81
85
 
82
- describe "#dot_grid_rows" do
83
- let(:pdf) { double('pdf') }
84
- let(:subject) { DotGrid::Page::Planner.new({:pdf => pdf }) }
85
- let(:square_grid_rows) { 10 }
86
+ before do
87
+ allow(pdf).to receive(:bounds).and_return(bounds)
88
+ end
86
89
 
87
- it "returns the foot height" do
88
- allow(subject).to receive(:square_grid_rows).and_return(square_grid_rows)
89
- expect(subject.dot_grid_rows).to eq(square_grid_rows+1)
90
+ it "returns the planner color 1" do
91
+ expect(subject.header_right_color).to eq("FFEEDD")
90
92
  end
91
93
  end
92
94
 
93
95
  describe "#footer_height" do
96
+ let(:bounds) { double('bounds', width: 10, height: 20) }
94
97
  let(:pdf) { double('pdf') }
95
98
  let(:subject) { DotGrid::Page::Planner.new({:pdf => pdf }) }
96
99
  let(:header_height) { 100 }
97
100
 
101
+ before do
102
+ allow(pdf).to receive(:bounds).and_return(bounds)
103
+ end
104
+
98
105
  it "returns the foot height" do
99
106
  allow(subject).to receive(:header_height).and_return(header_height)
100
107
  expect(subject.footer_height).to eq(header_height*DotGrid::Page::Planner::FOOT_HEIGHT_RATIO)
@@ -102,40 +109,21 @@ describe "DotGrid::Page::Planner" do
102
109
  end
103
110
 
104
111
  describe "#generate" do
105
- let(:pdf) { double('pdf') }
112
+ let(:pdf) { double('pdf', bounds: double('bounds', width: 10, height: 20)) }
106
113
  let(:subject) { DotGrid::Page::Planner.new({:pdf => pdf }) }
107
114
 
108
115
  before do
109
116
  allow(subject).to receive(:page_width).and_return(10)
110
117
  allow(subject).to receive(:page_height).and_return(20)
111
118
  allow(pdf).to receive(:start_new_page)
112
- allow(pdf).to receive(:fill_color)
113
- allow(pdf).to receive(:fill_rectangle)
114
- allow(pdf).to receive(:fill_circle)
115
- end
116
-
117
- it "starts a new page" do
118
- expect(pdf).to receive(:start_new_page)
119
- subject.generate
120
- end
121
-
122
- it "gets the page_width" do
123
- expect(subject).to receive(:page_width)
124
- subject.generate
125
- end
126
-
127
- it "gets the page_height" do
128
- expect(subject).to receive(:page_height)
129
- subject.generate
130
- end
131
-
132
- it "draws the left square grid" do
133
- expect(subject).to receive(:draw_square_grid_left)
134
- subject.generate
119
+ allow(subject).to receive(:draw_header).twice
120
+ allow(subject).to receive(:draw_footer)
121
+ allow_any_instance_of(::DotGrid::Pattern::SquareGrid).to receive(:draw)
122
+ allow_any_instance_of(::DotGrid::Pattern::DotGrid).to receive(:draw)
135
123
  end
136
124
 
137
- it "draws the dot grid" do
138
- expect(subject).to receive(:draw_dot_grid)
125
+ it "draws the header" do
126
+ expect(subject).to receive(:draw_header).twice
139
127
  subject.generate
140
128
  end
141
129
 
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe "DotGrid::Pattern::Checkerboard" do
4
4
  let(:pdf) { double('pdf') }
5
- let(:params) { { pdf: pdf, bounds: double('bounds', { height: 20.mm, width: 10.mm } ), spacing: 5 } }
5
+ let(:params) { { pdf: pdf, bounds: double('bounds', { upper_left: [0, 0], height: 20.mm, width: 10.mm } ), spacing: 5 } }
6
6
  let(:subject) { DotGrid::Pattern::Checkerboard.new(params) }
7
7
 
8
8
  describe "#rows" do
@@ -21,6 +21,7 @@ describe "DotGrid::Pattern::Checkerboard" do
21
21
  before do
22
22
  allow(pdf).to receive(:fill_color)
23
23
  allow(pdf).to receive(:fill_rectangle)
24
+ allow(pdf).to receive(:bounding_box).and_yield
24
25
  end
25
26
 
26
27
  it "sets the fill color" do
@@ -3,10 +3,11 @@ require 'spec_helper'
3
3
  describe "DotGrid::Pattern::DotGrid" do
4
4
  describe "#draw" do
5
5
  let(:pdf) { double('pdf') }
6
- let(:params) { { pdf: pdf, bounds: double('bounds', { height: 20.mm, width: 10.mm } ), spacing: 5 } }
6
+ let(:params) { { pdf: pdf, bounds: double('bounds', { upper_left: [0, 0], height: 20.mm, width: 10.mm } ), spacing: 5 } }
7
7
  let(:subject) { DotGrid::Pattern::DotGrid.new(params) }
8
8
 
9
9
  before do
10
+ allow(pdf).to receive(:bounding_box).and_yield
10
11
  allow(pdf).to receive(:fill_color)
11
12
  allow(pdf).to receive(:fill_circle)
12
13
  end
@@ -3,11 +3,12 @@ require 'spec_helper'
3
3
  describe "DotGrid::Pattern::Grid" do
4
4
  describe "#draw" do
5
5
  let(:pdf) { double('pdf') }
6
- let(:params) { { pdf: pdf, bounds: double('bounds', { height: 20.mm, width: 10.mm } ), spacing: 5 } }
6
+ let(:params) { { pdf: pdf, bounds: double('bounds', { upper_left: [0, 0], height: 20.mm, width: 10.mm } ), spacing: 5 } }
7
7
  let(:subject) { DotGrid::Pattern::Grid.new(params) }
8
8
 
9
9
  before do
10
10
  allow(pdf).to receive(:stroke_color)
11
+ allow(pdf).to receive(:bounding_box).and_yield
11
12
  allow(pdf).to receive(:stroke_horizontal_line)
12
13
  allow(pdf).to receive(:stroke_vertical_line)
13
14
  end
@@ -17,7 +18,7 @@ describe "DotGrid::Pattern::Grid" do
17
18
  subject.draw
18
19
  end
19
20
 
20
- it "draws teh horizontal lines" do
21
+ it "draws the horizontal lines" do
21
22
  allow(subject).to receive(:rows).and_return(2)
22
23
  expect(pdf).to receive(:stroke_horizontal_line).exactly(3).times
23
24
  subject.draw
@@ -4,10 +4,11 @@ describe "DotGrid::Pattern::HorizontalRule" do
4
4
 
5
5
  describe "#draw" do
6
6
  let(:pdf) { double('pdf') }
7
- let(:params) { { pdf: pdf, bounds: double('bounds', { height: 20.mm, width: 10.mm } ), spacing: 5 } }
7
+ let(:params) { { pdf: pdf, bounds: double('bounds', { upper_left: [0, 0], height: 20.mm, width: 10.mm } ), spacing: 5 } }
8
8
  let(:subject) { DotGrid::Pattern::HorizontalRule.new(params) }
9
9
 
10
10
  before do
11
+ allow(pdf).to receive(:bounding_box).and_yield
11
12
  allow(pdf).to receive(:stroke_color)
12
13
  allow(pdf).to receive(:stroke_horizontal_line)
13
14
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe "DotGrid::Pattern::Pattern" do
4
4
 
5
5
  let(:pdf) { double('pdf') }
6
- let(:params) { { pdf: pdf, bounds: double('bounds', { height: 20.mm, width: 10.mm } ), spacing: 5 } }
6
+ let(:params) { { pdf: pdf, bounds: double('bounds', { upper_left: [0, 0], height: 20.mm, width: 10.mm } ), spacing: 5 } }
7
7
  let(:subject) { DotGrid::Pattern::Pattern.new(params) }
8
8
 
9
9
  describe "#new" do
@@ -36,4 +36,13 @@ describe "DotGrid::Pattern::Pattern" do
36
36
  expect { subject.draw }.to raise_error
37
37
  end
38
38
  end
39
+
40
+ describe "#draw_grid" do
41
+ let(:pdf) { double('null object').as_null_object }
42
+
43
+ it "sets the bounding box" do
44
+ expect(pdf).to receive(:bounding_box)
45
+ subject.draw_grid
46
+ end
47
+ end
39
48
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dot_grid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott LaBounty
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-21 00:00:00.000000000 Z
11
+ date: 2014-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -115,6 +115,7 @@ files:
115
115
  - bin/dotgrid
116
116
  - dot_grid.gemspec
117
117
  - lib/dot_grid.rb
118
+ - lib/dot_grid/bounding_box.rb
118
119
  - lib/dot_grid/generator.rb
119
120
  - lib/dot_grid/page/checkerboard.rb
120
121
  - lib/dot_grid/page/dot_grid.rb
@@ -127,12 +128,14 @@ files:
127
128
  - lib/dot_grid/pattern/grid.rb
128
129
  - lib/dot_grid/pattern/horizontal_rule.rb
129
130
  - lib/dot_grid/pattern/pattern.rb
131
+ - lib/dot_grid/pattern/square_grid.rb
130
132
  - lib/dot_grid/version.rb
131
133
  - spec/lib/dot_grid/generator_spec.rb
132
134
  - spec/lib/dot_grid/page/checkerboard_spec.rb
133
135
  - spec/lib/dot_grid/page/dot_grid_spec.rb
134
136
  - spec/lib/dot_grid/page/grid_spec.rb
135
137
  - spec/lib/dot_grid/page/horizontal_rule_spec.rb
138
+ - spec/lib/dot_grid/page/page_spec.rb
136
139
  - spec/lib/dot_grid/page/planner_spec.rb
137
140
  - spec/lib/dot_grid/pattern/checkerboard_spec.rb
138
141
  - spec/lib/dot_grid/pattern/dot_grid_spec.rb
@@ -170,6 +173,7 @@ test_files:
170
173
  - spec/lib/dot_grid/page/dot_grid_spec.rb
171
174
  - spec/lib/dot_grid/page/grid_spec.rb
172
175
  - spec/lib/dot_grid/page/horizontal_rule_spec.rb
176
+ - spec/lib/dot_grid/page/page_spec.rb
173
177
  - spec/lib/dot_grid/page/planner_spec.rb
174
178
  - spec/lib/dot_grid/pattern/checkerboard_spec.rb
175
179
  - spec/lib/dot_grid/pattern/dot_grid_spec.rb