Class: Arrolio::Style::Definition

Inherits:
Object
  • Object
show all
Defined in:
lib/arrolio/style/definition.rb

Constant Summary collapse

DEFAULTS =
{
  font_name: 'Helvetica', font_size: 12.0,
  fill_color: nil, stroke_color: nil,
  line_spacing: 1.2, align: :left, valign: :top,
  margin_top: 0.0, margin_right: 0.0, margin_bottom: 0.0, margin_left: 0.0,
  padding_top: 0.0, padding_right: 0.0, padding_bottom: 0.0, padding_left: 0.0,
  character_spacing: 0.0, word_spacing: 0.0,
  line_break: :greedy,
  keep_together: false, page_break_before: false, page_break_after: false,
  keep_with_next: false, widows: 2, orphans: 2, parent: nil
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**opts) ⇒ Definition

Returns a new instance of Definition.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/arrolio/style/definition.rb', line 26

def initialize(**opts)
  merged = DEFAULTS.merge(opts.transform_keys(&:to_sym))
  @font_name = merged.fetch(:font_name).to_s
  @font_size = (merged.fetch(:font_size) || 0).to_f
  @fill_color = merged.fetch(:fill_color)
  @stroke_color = merged.fetch(:stroke_color)
  @line_spacing = (merged.fetch(:line_spacing) || 0).to_f
  @align = merged.fetch(:align).to_sym
  @valign = merged.fetch(:valign).to_sym
  @margin_top = (merged.fetch(:margin_top) || 0).to_f
  @margin_right = (merged.fetch(:margin_right) || 0).to_f
  @margin_bottom = (merged.fetch(:margin_bottom) || 0).to_f
  @margin_left = (merged.fetch(:margin_left) || 0).to_f
  @padding_top = (merged.fetch(:padding_top) || 0).to_f
  @padding_right = (merged.fetch(:padding_right) || 0).to_f
  @padding_bottom = (merged.fetch(:padding_bottom) || 0).to_f
  @padding_left = (merged.fetch(:padding_left) || 0).to_f
  @character_spacing = (merged.fetch(:character_spacing) || 0).to_f
  @word_spacing = (merged.fetch(:word_spacing) || 0).to_f
  @line_break = merged.fetch(:line_break).to_sym
  @keep_together = truthy?(merged.fetch(:keep_together))
  @page_break_before = truthy?(merged.fetch(:page_break_before))
  @page_break_after = truthy?(merged.fetch(:page_break_after))
  @keep_with_next = truthy?(merged.fetch(:keep_with_next))
  @widows = merged.fetch(:widows).to_i
  @orphans = merged.fetch(:orphans).to_i
  @parent = merged.fetch(:parent)
  freeze
end

Instance Attribute Details

#alignObject (readonly)

Returns the value of attribute align.



6
7
8
# File 'lib/arrolio/style/definition.rb', line 6

def align
  @align
end

#character_spacingObject (readonly)

Returns the value of attribute character_spacing.



6
7
8
# File 'lib/arrolio/style/definition.rb', line 6

def character_spacing
  @character_spacing
end

#fill_colorObject (readonly)

Returns the value of attribute fill_color.



6
7
8
# File 'lib/arrolio/style/definition.rb', line 6

def fill_color
  @fill_color
end

#font_nameObject (readonly)

Returns the value of attribute font_name.



6
7
8
# File 'lib/arrolio/style/definition.rb', line 6

def font_name
  @font_name
end

#font_sizeObject (readonly)

Returns the value of attribute font_size.



6
7
8
# File 'lib/arrolio/style/definition.rb', line 6

def font_size
  @font_size
end

#keep_togetherObject (readonly)

Returns the value of attribute keep_together.



6
7
8
# File 'lib/arrolio/style/definition.rb', line 6

def keep_together
  @keep_together
end

#keep_with_nextObject (readonly)

Returns the value of attribute keep_with_next.



6
7
8
# File 'lib/arrolio/style/definition.rb', line 6

def keep_with_next
  @keep_with_next
end

#line_breakObject (readonly)

Returns the value of attribute line_break.



6
7
8
# File 'lib/arrolio/style/definition.rb', line 6

def line_break
  @line_break
end

#line_spacingObject (readonly)

Returns the value of attribute line_spacing.



6
7
8
# File 'lib/arrolio/style/definition.rb', line 6

def line_spacing
  @line_spacing
end

#margin_bottomObject (readonly)

Returns the value of attribute margin_bottom.



6
7
8
# File 'lib/arrolio/style/definition.rb', line 6

def margin_bottom
  @margin_bottom
end

#margin_leftObject (readonly)

Returns the value of attribute margin_left.



6
7
8
# File 'lib/arrolio/style/definition.rb', line 6

def margin_left
  @margin_left
end

#margin_rightObject (readonly)

Returns the value of attribute margin_right.



6
7
8
# File 'lib/arrolio/style/definition.rb', line 6

def margin_right
  @margin_right
end

#margin_topObject (readonly)

Returns the value of attribute margin_top.



6
7
8
# File 'lib/arrolio/style/definition.rb', line 6

def margin_top
  @margin_top
end

#orphansObject (readonly)

Returns the value of attribute orphans.



6
7
8
# File 'lib/arrolio/style/definition.rb', line 6

def orphans
  @orphans
end

#padding_bottomObject (readonly)

Returns the value of attribute padding_bottom.



6
7
8
# File 'lib/arrolio/style/definition.rb', line 6

def padding_bottom
  @padding_bottom
end

#padding_leftObject (readonly)

Returns the value of attribute padding_left.



6
7
8
# File 'lib/arrolio/style/definition.rb', line 6

def padding_left
  @padding_left
end

#padding_rightObject (readonly)

Returns the value of attribute padding_right.



6
7
8
# File 'lib/arrolio/style/definition.rb', line 6

def padding_right
  @padding_right
end

#padding_topObject (readonly)

Returns the value of attribute padding_top.



6
7
8
# File 'lib/arrolio/style/definition.rb', line 6

def padding_top
  @padding_top
end

#page_break_afterObject (readonly)

Returns the value of attribute page_break_after.



6
7
8
# File 'lib/arrolio/style/definition.rb', line 6

def page_break_after
  @page_break_after
end

#page_break_beforeObject (readonly)

Returns the value of attribute page_break_before.



6
7
8
# File 'lib/arrolio/style/definition.rb', line 6

def page_break_before
  @page_break_before
end

#parentObject (readonly)

Returns the value of attribute parent.



6
7
8
# File 'lib/arrolio/style/definition.rb', line 6

def parent
  @parent
end

#stroke_colorObject (readonly)

Returns the value of attribute stroke_color.



6
7
8
# File 'lib/arrolio/style/definition.rb', line 6

def stroke_color
  @stroke_color
end

#valignObject (readonly)

Returns the value of attribute valign.



6
7
8
# File 'lib/arrolio/style/definition.rb', line 6

def valign
  @valign
end

#widowsObject (readonly)

Returns the value of attribute widows.



6
7
8
# File 'lib/arrolio/style/definition.rb', line 6

def widows
  @widows
end

#word_spacingObject (readonly)

Returns the value of attribute word_spacing.



6
7
8
# File 'lib/arrolio/style/definition.rb', line 6

def word_spacing
  @word_spacing
end

Instance Method Details

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



63
64
65
# File 'lib/arrolio/style/definition.rb', line 63

def ==(other)
  other.is_a?(self.class) && to_h == other.to_h
end

#hashObject



68
# File 'lib/arrolio/style/definition.rb', line 68

def hash = to_h.hash

#space_afterObject



61
# File 'lib/arrolio/style/definition.rb', line 61

def space_after = @margin_bottom

#space_beforeObject



60
# File 'lib/arrolio/style/definition.rb', line 60

def space_before = @margin_top

#to_hObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/arrolio/style/definition.rb', line 70

def to_h
  {
    font_name: @font_name, font_size: @font_size,
    fill_color: @fill_color, stroke_color: @stroke_color,
    line_spacing: @line_spacing, align: @align, valign: @valign,
    margin_top: @margin_top, margin_right: @margin_right,
    margin_bottom: @margin_bottom, margin_left: @margin_left,
    padding_top: @padding_top, padding_right: @padding_right,
    padding_bottom: @padding_bottom, padding_left: @padding_left,
    character_spacing: @character_spacing, word_spacing: @word_spacing,
    line_break: @line_break, keep_together: @keep_together,
    page_break_before: @page_break_before, page_break_after: @page_break_after,
    keep_with_next: @keep_with_next, widows: @widows, orphans: @orphans,
    parent: @parent
  }
end

#with(**opts) ⇒ Object



56
57
58
# File 'lib/arrolio/style/definition.rb', line 56

def with(**opts)
  self.class.new(**to_h, **opts.transform_keys(&:to_sym))
end