Class: DotGrid::Pattern::Pattern

Inherits:
Object
  • Object
show all
Defined in:
lib/dot_grid/pattern/pattern.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Pattern

Returns a new instance of Pattern.



11
12
13
14
15
16
17
# File 'lib/dot_grid/pattern/pattern.rb', line 11

def initialize(params = {})
  @pdf = params[:pdf]
  @bounds = params[:bounds] || ::DotGrid::BoundingBox.new(upper_left: [0, pdf.bounds.height], width: pdf.bounds.width, height: pdf.bounds.height)
  @grid_color = params[:grid_color] || "B3B3B3"
  @spacing = params[:spacing] ? params[:spacing].mm : 5.mm
  post_initialize(params)
end

Instance Attribute Details

#boundsObject

Returns the value of attribute bounds.



4
5
6
# File 'lib/dot_grid/pattern/pattern.rb', line 4

def bounds
  @bounds
end

#grid_colorObject

Returns the value of attribute grid_color.



4
5
6
# File 'lib/dot_grid/pattern/pattern.rb', line 4

def grid_color
  @grid_color
end

#pdfObject

Returns the value of attribute pdf.



4
5
6
# File 'lib/dot_grid/pattern/pattern.rb', line 4

def pdf
  @pdf
end

Instance Method Details

#columnsObject



27
28
29
# File 'lib/dot_grid/pattern/pattern.rb', line 27

def columns
  (bounds.width / spacing).floor
end

#drawObject

Raises:

  • (NotImplementedError)


41
42
43
# File 'lib/dot_grid/pattern/pattern.rb', line 41

def draw
  raise NotImplementedError
end

#draw_grid(shorten = false) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/dot_grid/pattern/pattern.rb', line 31

def draw_grid(shorten = false)
  pdf.bounding_box(bounds.upper_left, width: bounds.width, height: bounds.height) do
    (0..(shorten ? rows-1 : rows)).each do |row|
      (0..(shorten ? columns-1 : columns)).each do |column|
        yield row, column
      end
    end
  end
end

#post_initialize(params) ⇒ Object



19
20
21
# File 'lib/dot_grid/pattern/pattern.rb', line 19

def post_initialize(params)
  nil
end

#rowsObject



23
24
25
# File 'lib/dot_grid/pattern/pattern.rb', line 23

def rows
  (bounds.height / spacing).floor
end