Class: Arrolio::Output::PlacedBox

Inherits:
Object
  • Object
show all
Defined in:
lib/arrolio/output/placed_box.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x:, y:, width:, height:, kind:, data: {}, link_dest: nil) ⇒ PlacedBox

Returns a new instance of PlacedBox.



8
9
10
11
12
13
14
15
16
17
# File 'lib/arrolio/output/placed_box.rb', line 8

def initialize(x:, y:, width:, height:, kind:, data: {}, link_dest: nil)
  @x = x.to_f
  @y = y.to_f
  @width = width.to_f
  @height = height.to_f
  @kind = kind
  @data = data.to_h.freeze
  @link_dest = link_dest
  freeze
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



6
7
8
# File 'lib/arrolio/output/placed_box.rb', line 6

def data
  @data
end

#heightObject (readonly)

Returns the value of attribute height.



6
7
8
# File 'lib/arrolio/output/placed_box.rb', line 6

def height
  @height
end

#kindObject (readonly)

Returns the value of attribute kind.



6
7
8
# File 'lib/arrolio/output/placed_box.rb', line 6

def kind
  @kind
end

Returns the value of attribute link_dest.



6
7
8
# File 'lib/arrolio/output/placed_box.rb', line 6

def link_dest
  @link_dest
end

#widthObject (readonly)

Returns the value of attribute width.



6
7
8
# File 'lib/arrolio/output/placed_box.rb', line 6

def width
  @width
end

#xObject (readonly)

Returns the value of attribute x.



6
7
8
# File 'lib/arrolio/output/placed_box.rb', line 6

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



6
7
8
# File 'lib/arrolio/output/placed_box.rb', line 6

def y
  @y
end

Class Method Details

.image(x:, y:, width:, height:, image_ref:, link_dest: nil) ⇒ Object



46
47
48
49
50
# File 'lib/arrolio/output/placed_box.rb', line 46

def image(x:, y:, width:, height:, image_ref:, link_dest: nil)
  new(x: x, y: y, width: width, height: height, kind: :image,
      data: { image_ref: image_ref },
      link_dest: link_dest)
end

.line(x1:, y1:, x2:, y2:, stroke_width: 0.5, stroke_color: nil) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/arrolio/output/placed_box.rb', line 36

def line(x1:, y1:, x2:, y2:, stroke_width: 0.5, stroke_color: nil)
  new(x: [x1, x2].min, y: [y1, y2].min,
      width: (x2 - x1).abs, height: (y2 - y1).abs,
      kind: :line,
      data: { x1: x1.to_f, y1: y1.to_f,
              x2: x2.to_f, y2: y2.to_f,
              stroke_width: stroke_width.to_f,
              stroke_color: stroke_color })
end

.rect(x:, y:, width:, height:, stroke_width: 0.5, stroke_color: nil, fill_color: nil) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/arrolio/output/placed_box.rb', line 28

def rect(x:, y:, width:, height:, stroke_width: 0.5,
         stroke_color: nil, fill_color: nil)
  new(x: x, y: y, width: width, height: height, kind: :rect,
      data: { stroke_width: stroke_width.to_f,
              stroke_color: stroke_color,
              fill_color: fill_color })
end

.text(x:, y:, width:, height:, lines:, line_height:, style:, link_dest: nil) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/arrolio/output/placed_box.rb', line 20

def text(x:, y:, width:, height:, lines:, line_height:, style:, link_dest: nil)
  new(x: x, y: y, width: width, height: height, kind: :text,
      data: { lines: Array(lines).freeze,
              line_height: line_height.to_f,
              style: style },
      link_dest: link_dest)
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



53
54
55
56
57
58
59
# File 'lib/arrolio/output/placed_box.rb', line 53

def ==(other)
  other.is_a?(self.class) &&
    x == other.x && y == other.y &&
    width == other.width && height == other.height &&
    kind == other.kind && data == other.data &&
    link_dest == other.link_dest
end

#hashObject



63
64
65
# File 'lib/arrolio/output/placed_box.rb', line 63

def hash
  [self.class, x, y, width, height, kind, data, link_dest].hash
end