Module: Uniword::Builder::HasBorders

Included in:
ParagraphBuilder, TableBuilder, TableCellBuilder
Defined in:
lib/uniword/builder/has_borders.rb

Overview

Mixin for builders that support border configuration.

Expects the including class to implement #ensure_properties returning the properties object that has a #borders accessor.

Instance Method Summary collapse

Instance Method Details

#borders(**sides) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/uniword/builder/has_borders.rb', line 10

def borders(**sides)
  props = ensure_properties
  props.borders ||= Properties::Borders.new
  sides.each do |side, value|
    border = if value.is_a?(Hash)
               Properties::Border.new(**value)
             else
               Properties::Border.new(color: value, style: "single",
                                      size: 4)
             end
    case side
    when :top     then props.borders.top = border
    when :bottom  then props.borders.bottom = border
    when :left    then props.borders.left = border
    when :right   then props.borders.right = border
    when :between then props.borders.between = border
    when :bar     then props.borders.bar = border
    end
  end
  self
end