Class: CSVPlusPlus::Modifier

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(row_level: false) ⇒ Modifier

Returns a new instance of Modifier.

Parameters:

  • row_level (Boolean) (defaults to: false)

    Whether or not this modifier applies to the entire row



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

#bordercolorString

Returns the current value of bordercolor.

Returns:

  • (String)

    the current value of bordercolor



26
27
28
# File 'lib/csv_plus_plus/modifier.rb', line 26

def bordercolor
  @bordercolor
end

#bordersArray<String>

Returns the current value of borders.

Returns:

  • (Array<String>)

    the current value of borders



26
27
28
# File 'lib/csv_plus_plus/modifier.rb', line 26

def borders
  @borders
end

#borderstyleString

Style of border

Returns:

  • (String)


147
148
149
# File 'lib/csv_plus_plus/modifier.rb', line 147

def borderstyle
  @borderstyle || 'solid'
end

#colorColor

The background color of the cell

Returns:

  • (Color)

    the current value of color



26
27
28
# File 'lib/csv_plus_plus/modifier.rb', line 26

def color
  @color
end

#expandExpand

Whether this row expands into multiple rows

Returns:

  • (Expand)

    the current value of expand



26
27
28
# File 'lib/csv_plus_plus/modifier.rb', line 26

def expand
  @expand
end

#fontcolorColor

The font color of the cell

Returns:

  • (Color)

    the current value of fontcolor



26
27
28
# File 'lib/csv_plus_plus/modifier.rb', line 26

def fontcolor
  @fontcolor
end

#fontfamilyString

The font family

Returns:

  • (String)

    the current value of fontfamily



26
27
28
# File 'lib/csv_plus_plus/modifier.rb', line 26

def fontfamily
  @fontfamily
end

#fontsizeNumber

The font size

Returns:

  • (Number)

    the current value of fontsize



26
27
28
# File 'lib/csv_plus_plus/modifier.rb', line 26

def fontsize
  @fontsize
end

#formatsArray<String> (readonly)

Bold/italics/underline/strikethrough formatting

Returns:

  • (Array<String>)

    the current value of formats



26
27
28
# File 'lib/csv_plus_plus/modifier.rb', line 26

def formats
  @formats
end

#halign'left', ...

Horizontal alignment

Returns:

  • ('left', 'center', 'right')

    the current value of halign



26
27
28
# File 'lib/csv_plus_plus/modifier.rb', line 26

def halign
  @halign
end

#noteString

A note/comment on the cell

Returns:

  • (String)

    the current value of note



26
27
28
# File 'lib/csv_plus_plus/modifier.rb', line 26

def note
  @note
end

#numberformatString

A number format to apply to the value in the cell

Returns:

  • (String)

    the current value of numberformat



26
27
28
# File 'lib/csv_plus_plus/modifier.rb', line 26

def numberformat
  @numberformat
end

#row_levelBoolean

Is this a row modifier? If so it’s values will apply to all cells in the row (unless overridden by the cell modifier)

Returns:

  • (Boolean)

    the current value of row_level



26
27
28
# File 'lib/csv_plus_plus/modifier.rb', line 26

def row_level
  @row_level
end

#validationObject

Returns the current value of validation.

Returns:

  • (Object)

    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

Returns:

  • ('top', 'center', 'bottom')

    the current value of valign



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?

Returns:

  • (Boolean)


82
83
84
# File 'lib/csv_plus_plus/modifier.rb', line 82

def any_border?
  !@borders.empty?
end

#border=(side) ⇒ Object

Assign a border

Parameters:

  • side ('top', 'left', 'bottom', 'right', 'all')


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?

Returns:

  • (Boolean)


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?

Parameters:

  • side ('top', 'left', 'bottom', 'right', 'all')

Returns:

  • (Boolean)


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?

Returns:

  • (Boolean)


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)

Parameters:

  • value ('bold', 'italic', 'underline', '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?

Parameters:

  • type ('bold', 'italic', 'underline', 'strikethrough')

Returns:

  • (Boolean)


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

Returns:

  • (true)


112
113
114
# File 'lib/csv_plus_plus/modifier.rb', line 112

def freeze!
  @frozen = true
end

#frozen?Boolean

Is the row frozen?

Returns:

  • (Boolean)


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

Returns:

  • (true)


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?

Returns:

  • (Boolean)


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

Parameters:



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_sString

Returns:

  • (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