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

initialize



17
18
19
20
21
22
23
# File 'lib/csv_plus_plus/modifier.rb', line 17

def initialize(row_level: false)
  @row_level = row_level
  @freeze = false
  @align = ::Set.new
  @borders = ::Set.new
  @formats = ::Set.new
end

Instance Attribute Details

#bordercolorObject

Returns the value of attribute bordercolor.



12
13
14
# File 'lib/csv_plus_plus/modifier.rb', line 12

def bordercolor
  @bordercolor
end

#bordersObject (readonly)

Returns the value of attribute borders.



12
13
14
# File 'lib/csv_plus_plus/modifier.rb', line 12

def borders
  @borders
end

#borderstyleObject

Style of border



106
107
108
# File 'lib/csv_plus_plus/modifier.rb', line 106

def borderstyle
  @borderstyle || 'solid'
end

#colorObject

Returns the value of attribute color.



12
13
14
# File 'lib/csv_plus_plus/modifier.rb', line 12

def color
  @color
end

#expandObject

Returns the value of attribute expand.



14
15
16
# File 'lib/csv_plus_plus/modifier.rb', line 14

def expand
  @expand
end

#fontcolorObject

Returns the value of attribute fontcolor.



12
13
14
# File 'lib/csv_plus_plus/modifier.rb', line 12

def fontcolor
  @fontcolor
end

#fontfamilyObject

Returns the value of attribute fontfamily.



14
15
16
# File 'lib/csv_plus_plus/modifier.rb', line 14

def fontfamily
  @fontfamily
end

#fontsizeObject

Returns the value of attribute fontsize.



14
15
16
# File 'lib/csv_plus_plus/modifier.rb', line 14

def fontsize
  @fontsize
end

#formatsObject (readonly)

Returns the value of attribute formats.



12
13
14
# File 'lib/csv_plus_plus/modifier.rb', line 12

def formats
  @formats
end

#noteObject

Returns the value of attribute note.



14
15
16
# File 'lib/csv_plus_plus/modifier.rb', line 14

def note
  @note
end

#numberformatObject

Returns the value of attribute numberformat.



14
15
16
# File 'lib/csv_plus_plus/modifier.rb', line 14

def numberformat
  @numberformat
end

#row_levelObject

Returns the value of attribute row_level.



14
15
16
# File 'lib/csv_plus_plus/modifier.rb', line 14

def row_level
  @row_level
end

#validationObject

Returns the value of attribute validation.



14
15
16
# File 'lib/csv_plus_plus/modifier.rb', line 14

def validation
  @validation
end

Instance Method Details

#align=(direction) ⇒ Object

Set an align format. direction must be ‘center’, ‘left’, ‘right’, ‘bottom’



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

def align=(direction)
  @align << direction
end

#aligned?(direction) ⇒ Boolean

Is it aligned to a given direction?

Returns:

  • (Boolean)


31
32
33
# File 'lib/csv_plus_plus/modifier.rb', line 31

def aligned?(direction)
  @align.include?(direction)
end

#any_border?Boolean

Are there any borders set?

Returns:

  • (Boolean)


61
62
63
# File 'lib/csv_plus_plus/modifier.rb', line 61

def any_border?
  !@borders.empty?
end

#border=(side) ⇒ Object

Assign a border. side must be ‘top’, ‘left’, ‘bottom’, ‘right’ or ‘all’



41
42
43
# File 'lib/csv_plus_plus/modifier.rb', line 41

def border=(side)
  @borders << side
end

#border_all?Boolean

Does this have a border along all sides?

Returns:

  • (Boolean)


51
52
53
# File 'lib/csv_plus_plus/modifier.rb', line 51

def border_all?
  @borders.include?('all')
end

#border_along?(side) ⇒ Boolean

Does this have a border along side?

Returns:

  • (Boolean)


46
47
48
# File 'lib/csv_plus_plus/modifier.rb', line 46

def border_along?(side)
  border_all? || @borders.include?(side)
end

#cell_level?Boolean

Is this a cell-level modifier?

Returns:

  • (Boolean)


101
102
103
# File 'lib/csv_plus_plus/modifier.rb', line 101

def cell_level?
  !@row_level
end

#format=(value) ⇒ Object

Set a format. type must be ‘bold’, ‘italic’, ‘underline’ or ‘strikethrough’



71
72
73
# File 'lib/csv_plus_plus/modifier.rb', line 71

def format=(value)
  @formats << value
end

#formatted?(type) ⇒ Boolean

Is the given format set?

Returns:

  • (Boolean)


76
77
78
# File 'lib/csv_plus_plus/modifier.rb', line 76

def formatted?(type)
  @formats.include?(type)
end

#freeze!Object

Freeze the row from edits



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

def freeze!
  @frozen = true
end

#frozen?Boolean

Is the row forzen?

Returns:

  • (Boolean)


86
87
88
# File 'lib/csv_plus_plus/modifier.rb', line 86

def frozen?
  @frozen
end

#row_level!Object

Mark this modifer as row-level



91
92
93
# File 'lib/csv_plus_plus/modifier.rb', line 91

def row_level!
  @row_level = true
end

#row_level?Boolean

Is this a row-level modifier?

Returns:

  • (Boolean)


96
97
98
# File 'lib/csv_plus_plus/modifier.rb', line 96

def row_level?
  @row_level
end

#take_defaults_from!(other) ⇒ Object

Create a new modifier instance, with all values defaulted from other



117
118
119
120
121
122
# File 'lib/csv_plus_plus/modifier.rb', line 117

def take_defaults_from!(other)
  instance_variables.each do |property|
    value = other.instance_variable_get(property)
    instance_variable_set(property, value.clone)
  end
end

#to_sObject

to_s



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

def to_s
  # TODO... I dunno, not sure how to manage this
  "Modifier(row_level: #{@row_level} align: #{@align} format: #{@formats} font_size: #{@font_size})"
end