Class: CSVPlusPlus::Modifier
- Inherits:
-
Object
- Object
- CSVPlusPlus::Modifier
- Defined in:
- lib/csv_plus_plus/modifier.rb
Overview
A container representing the operations that can be applied to a cell or row
Instance Attribute Summary collapse
-
#bordercolor ⇒ String
The current value of bordercolor.
-
#borders ⇒ Array<String>
The current value of borders.
-
#borderstyle ⇒ String
Style of border.
-
#color ⇒ Color
The background color of the cell.
-
#expand ⇒ Expand
Whether this row expands into multiple rows.
-
#fontcolor ⇒ Color
The font color of the cell.
-
#fontfamily ⇒ String
The font family.
-
#fontsize ⇒ Number
The font size.
-
#formats ⇒ Array<String>
readonly
Bold/italics/underline/strikethrough formatting.
-
#halign ⇒ 'left', ...
Horizontal alignment.
-
#note ⇒ String
A note/comment on the cell.
-
#numberformat ⇒ String
A number format to apply to the value in the cell.
-
#row_level ⇒ Boolean
Is this a row modifier? If so it’s values will apply to all cells in the row (unless overridden by the cell modifier).
-
#validation ⇒ Object
The current value of validation.
-
#valign ⇒ 'top', ...
Vertical alignment.
Instance Method Summary collapse
-
#any_border? ⇒ Boolean
Are there any borders set?.
-
#border=(side) ⇒ Object
Assign a border.
-
#border_all? ⇒ Boolean
Does this have a border along all sides?.
-
#border_along?(side) ⇒ Boolean
Does this have a border along
side?. -
#cell_level? ⇒ Boolean
Is this a cell-level modifier?.
-
#format=(value) ⇒ Object
Set a text format (bolid, italic, underline or strikethrough).
-
#formatted?(type) ⇒ Boolean
Is the given format set?.
-
#freeze! ⇒ true
Freeze the row from edits.
-
#frozen? ⇒ Boolean
Is the row frozen?.
-
#initialize(row_level: false) ⇒ Modifier
constructor
A new instance of Modifier.
-
#row_level! ⇒ true
Mark this modifer as row-level.
-
#row_level? ⇒ Boolean
Is this a row-level modifier?.
-
#take_defaults_from!(other) ⇒ Object
Create a new modifier instance, with all values defaulted from
other. - #to_s ⇒ String
Constructor Details
#initialize(row_level: false) ⇒ Modifier
Returns a new instance of Modifier.
32 33 34 35 36 37 |
# File 'lib/csv_plus_plus/modifier.rb', line 32 def initialize(row_level: false) @row_level = row_level @freeze = false @borders = ::Set.new @formats = ::Set.new end |
Instance Attribute Details
#bordercolor ⇒ String
Returns the current value of bordercolor.
26 27 28 |
# File 'lib/csv_plus_plus/modifier.rb', line 26 def bordercolor @bordercolor end |
#borders ⇒ Array<String>
Returns the current value of borders.
26 27 28 |
# File 'lib/csv_plus_plus/modifier.rb', line 26 def borders @borders end |
#borderstyle ⇒ String
Style of border
147 148 149 |
# File 'lib/csv_plus_plus/modifier.rb', line 147 def borderstyle @borderstyle || 'solid' end |
#color ⇒ Color
The background color of the cell
26 27 28 |
# File 'lib/csv_plus_plus/modifier.rb', line 26 def color @color end |
#expand ⇒ Expand
Whether this row expands into multiple rows
26 27 28 |
# File 'lib/csv_plus_plus/modifier.rb', line 26 def @expand end |
#fontcolor ⇒ Color
The font color of the cell
26 27 28 |
# File 'lib/csv_plus_plus/modifier.rb', line 26 def fontcolor @fontcolor end |
#fontfamily ⇒ String
The font family
26 27 28 |
# File 'lib/csv_plus_plus/modifier.rb', line 26 def fontfamily @fontfamily end |
#fontsize ⇒ Number
The font size
26 27 28 |
# File 'lib/csv_plus_plus/modifier.rb', line 26 def fontsize @fontsize end |
#formats ⇒ Array<String> (readonly)
Bold/italics/underline/strikethrough formatting
26 27 28 |
# File 'lib/csv_plus_plus/modifier.rb', line 26 def formats @formats end |
#halign ⇒ 'left', ...
Horizontal alignment
26 27 28 |
# File 'lib/csv_plus_plus/modifier.rb', line 26 def halign @halign end |
#note ⇒ String
A note/comment on the cell
26 27 28 |
# File 'lib/csv_plus_plus/modifier.rb', line 26 def note @note end |
#numberformat ⇒ String
A number format to apply to the value in the cell
26 27 28 |
# File 'lib/csv_plus_plus/modifier.rb', line 26 def numberformat @numberformat end |
#row_level ⇒ Boolean
Is this a row modifier? If so it’s values will apply to all cells in the row (unless overridden by the cell modifier)
26 27 28 |
# File 'lib/csv_plus_plus/modifier.rb', line 26 def row_level @row_level end |
#validation ⇒ Object
Returns the current value of validation.
26 27 28 |
# File 'lib/csv_plus_plus/modifier.rb', line 26 def validation @validation end |
#valign ⇒ 'top', ...
Vertical alignment
26 27 28 |
# File 'lib/csv_plus_plus/modifier.rb', line 26 def valign @valign end |
Instance Method Details
#any_border? ⇒ Boolean
Are there any borders set?
82 83 84 |
# File 'lib/csv_plus_plus/modifier.rb', line 82 def any_border? !@borders.empty? end |
#border=(side) ⇒ Object
Assign a border
51 52 53 |
# File 'lib/csv_plus_plus/modifier.rb', line 51 def border=(side) @borders << side end |
#border_all? ⇒ Boolean
Does this have a border along all sides?
67 68 69 70 |
# File 'lib/csv_plus_plus/modifier.rb', line 67 def border_all? @borders.include?('all') \ || (border_along?('top') && border_along?('bottom') && border_along?('left') && border_along?('right')) end |
#border_along?(side) ⇒ Boolean
Does this have a border along side?
60 61 62 |
# File 'lib/csv_plus_plus/modifier.rb', line 60 def border_along?(side) @borders.include?('all') || @borders.include?(side) end |
#cell_level? ⇒ Boolean
Is this a cell-level modifier?
140 141 142 |
# File 'lib/csv_plus_plus/modifier.rb', line 140 def cell_level? !@row_level end |
#format=(value) ⇒ Object
Set a text format (bolid, italic, underline or strikethrough)
96 97 98 |
# File 'lib/csv_plus_plus/modifier.rb', line 96 def format=(value) @formats << value end |
#formatted?(type) ⇒ Boolean
Is the given format set?
105 106 107 |
# File 'lib/csv_plus_plus/modifier.rb', line 105 def formatted?(type) @formats.include?(type) end |
#freeze! ⇒ true
Freeze the row from edits
112 113 114 |
# File 'lib/csv_plus_plus/modifier.rb', line 112 def freeze! @frozen = true end |
#frozen? ⇒ Boolean
Is the row frozen?
119 120 121 |
# File 'lib/csv_plus_plus/modifier.rb', line 119 def frozen? @frozen end |
#row_level! ⇒ true
Mark this modifer as row-level
126 127 128 |
# File 'lib/csv_plus_plus/modifier.rb', line 126 def row_level! @row_level = true end |
#row_level? ⇒ Boolean
Is this a row-level modifier?
133 134 135 |
# File 'lib/csv_plus_plus/modifier.rb', line 133 def row_level? @row_level end |
#take_defaults_from!(other) ⇒ Object
Create a new modifier instance, with all values defaulted from other
161 162 163 164 165 166 167 168 169 |
# File 'lib/csv_plus_plus/modifier.rb', line 161 def take_defaults_from!(other) other.instance_variables.each do |property| # don't propagate row-specific values next if property == :@row_level value = other.instance_variable_get(property) instance_variable_set(property, value.clone) end end |
#to_s ⇒ String
152 153 154 155 156 |
# File 'lib/csv_plus_plus/modifier.rb', line 152 def to_s # TODO... I dunno, not sure how to manage this "Modifier(row_level: #{@row_level} halign: #{@halign} valign: #{@valign} format: #{@formats} " \ "font_size: #{@font_size})" end |