Class: Arrolio::Style::Definition
- Inherits:
-
Object
- Object
- Arrolio::Style::Definition
- 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
-
#align ⇒ Object
readonly
Returns the value of attribute align.
-
#character_spacing ⇒ Object
readonly
Returns the value of attribute character_spacing.
-
#fill_color ⇒ Object
readonly
Returns the value of attribute fill_color.
-
#font_name ⇒ Object
readonly
Returns the value of attribute font_name.
-
#font_size ⇒ Object
readonly
Returns the value of attribute font_size.
-
#keep_together ⇒ Object
readonly
Returns the value of attribute keep_together.
-
#keep_with_next ⇒ Object
readonly
Returns the value of attribute keep_with_next.
-
#line_break ⇒ Object
readonly
Returns the value of attribute line_break.
-
#line_spacing ⇒ Object
readonly
Returns the value of attribute line_spacing.
-
#margin_bottom ⇒ Object
readonly
Returns the value of attribute margin_bottom.
-
#margin_left ⇒ Object
readonly
Returns the value of attribute margin_left.
-
#margin_right ⇒ Object
readonly
Returns the value of attribute margin_right.
-
#margin_top ⇒ Object
readonly
Returns the value of attribute margin_top.
-
#orphans ⇒ Object
readonly
Returns the value of attribute orphans.
-
#padding_bottom ⇒ Object
readonly
Returns the value of attribute padding_bottom.
-
#padding_left ⇒ Object
readonly
Returns the value of attribute padding_left.
-
#padding_right ⇒ Object
readonly
Returns the value of attribute padding_right.
-
#padding_top ⇒ Object
readonly
Returns the value of attribute padding_top.
-
#page_break_after ⇒ Object
readonly
Returns the value of attribute page_break_after.
-
#page_break_before ⇒ Object
readonly
Returns the value of attribute page_break_before.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#stroke_color ⇒ Object
readonly
Returns the value of attribute stroke_color.
-
#valign ⇒ Object
readonly
Returns the value of attribute valign.
-
#widows ⇒ Object
readonly
Returns the value of attribute widows.
-
#word_spacing ⇒ Object
readonly
Returns the value of attribute word_spacing.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(**opts) ⇒ Definition
constructor
A new instance of Definition.
- #space_after ⇒ Object
- #space_before ⇒ Object
- #to_h ⇒ Object
- #with(**opts) ⇒ Object
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
#align ⇒ Object (readonly)
Returns the value of attribute align.
6 7 8 |
# File 'lib/arrolio/style/definition.rb', line 6 def align @align end |
#character_spacing ⇒ Object (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_color ⇒ Object (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_name ⇒ Object (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_size ⇒ Object (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_together ⇒ Object (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_next ⇒ Object (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_break ⇒ Object (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_spacing ⇒ Object (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_bottom ⇒ Object (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_left ⇒ Object (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_right ⇒ Object (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_top ⇒ Object (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 |
#orphans ⇒ Object (readonly)
Returns the value of attribute orphans.
6 7 8 |
# File 'lib/arrolio/style/definition.rb', line 6 def orphans @orphans end |
#padding_bottom ⇒ Object (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_left ⇒ Object (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_right ⇒ Object (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_top ⇒ Object (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_after ⇒ Object (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_before ⇒ Object (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 |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
6 7 8 |
# File 'lib/arrolio/style/definition.rb', line 6 def parent @parent end |
#stroke_color ⇒ Object (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 |
#valign ⇒ Object (readonly)
Returns the value of attribute valign.
6 7 8 |
# File 'lib/arrolio/style/definition.rb', line 6 def valign @valign end |
#widows ⇒ Object (readonly)
Returns the value of attribute widows.
6 7 8 |
# File 'lib/arrolio/style/definition.rb', line 6 def widows @widows end |
#word_spacing ⇒ Object (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 |
#hash ⇒ Object
68 |
# File 'lib/arrolio/style/definition.rb', line 68 def hash = to_h.hash |
#space_after ⇒ Object
61 |
# File 'lib/arrolio/style/definition.rb', line 61 def space_after = @margin_bottom |
#space_before ⇒ Object
60 |
# File 'lib/arrolio/style/definition.rb', line 60 def space_before = @margin_top |
#to_h ⇒ Object
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 |