csv_plus_plus 0.0.3 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,73 +6,91 @@ require_relative './expand'
6
6
  require_relative './language/syntax_error'
7
7
 
8
8
  module CSVPlusPlus
9
- ##
10
9
  # A container representing the operations that can be applied to a cell or row
10
+ #
11
+ # @attr expand [Expand]
12
+ # @attr fontfamily [String]
13
+ # @attr fontsize [String]
14
+ # @attr halign ['left', 'center', 'right']
15
+ # @attr valign ['top', 'center', 'bottom']
16
+ # @attr note [String]
17
+ # @attr numberformat [String]
18
+ # @attr row_level [Boolean]
19
+ # @attr validation [Object]
20
+ #
21
+ # @attr_writer borderstyle [String]
22
+ #
23
+ # @attr_reader bordercolor [String]
24
+ # @attr_reader borders [Array<String>]
25
+ # @attr_reader color [Color]
26
+ # @attr_reader fontcolor [Color]
27
+ # @attr_reader formats [Array<String>]
11
28
  class Modifier
12
29
  attr_reader :bordercolor, :borders, :color, :fontcolor, :formats
13
30
  attr_writer :borderstyle
14
- attr_accessor :expand, :fontfamily, :fontsize, :note, :numberformat, :row_level, :validation
31
+ attr_accessor :expand, :fontfamily, :fontsize, :halign, :valign, :note, :numberformat, :row_level, :validation
15
32
 
16
- # initialize
33
+ # @param row_level [Boolean] Whether or not this modifier applies to the entire row
17
34
  def initialize(row_level: false)
18
35
  @row_level = row_level
19
36
  @freeze = false
20
- @align = ::Set.new
21
37
  @borders = ::Set.new
22
38
  @formats = ::Set.new
23
39
  end
24
40
 
25
- # Set an align format. +direction+ must be 'center', 'left', 'right', 'bottom'
26
- def align=(direction)
27
- @align << direction
28
- end
29
-
30
- # Is it aligned to a given direction?
31
- def aligned?(direction)
32
- @align.include?(direction)
33
- end
34
-
35
- # Set the color. hex_value is a String
41
+ # Set the color
42
+ # @param hex_value [String]
36
43
  def color=(hex_value)
37
44
  @color = ::CSVPlusPlus::Color.new(hex_value)
38
45
  end
39
46
 
40
- # Assign a border. +side+ must be 'top', 'left', 'bottom', 'right' or 'all'
47
+ # Assign a border
48
+ # @param side ['top', 'left', 'bottom', 'right', 'all']
41
49
  def border=(side)
42
50
  @borders << side
43
51
  end
44
52
 
45
53
  # Does this have a border along +side+?
54
+ # @param side ['top', 'left', 'bottom', 'right', 'all']
55
+ # @return [Boolean]
46
56
  def border_along?(side)
47
- border_all? || @borders.include?(side)
57
+ @borders.include?('all') || @borders.include?(side)
48
58
  end
49
59
 
50
60
  # Does this have a border along all sides?
61
+ # @return [Boolean]
51
62
  def border_all?
52
- @borders.include?('all')
63
+ @borders.include?('all') \
64
+ || (border_along?('top') && border_along?('bottom') && border_along?('left') && border_along?('right'))
53
65
  end
54
66
 
55
67
  # Set the bordercolor
68
+ # @param hex_value [String] formatted as '#000000', '#000' or '000000'
56
69
  def bordercolor=(hex_value)
57
70
  @bordercolor = ::CSVPlusPlus::Color.new(hex_value)
58
71
  end
59
72
 
60
73
  # Are there any borders set?
74
+ # @return [Boolean]
61
75
  def any_border?
62
76
  !@borders.empty?
63
77
  end
64
78
 
65
79
  # Set the fontcolor
80
+ # @param hex_value [String] formatted as '#000000', '#000' or '000000'
66
81
  def fontcolor=(hex_value)
67
82
  @fontcolor = ::CSVPlusPlus::Color.new(hex_value)
68
83
  end
69
84
 
70
- # Set a format. +type+ must be 'bold', 'italic', 'underline' or 'strikethrough'
85
+ # Set a text format (bolid, italic, underline or strikethrough)
86
+ # @param value ['bold', 'italic', 'underline', 'strikethrough']
71
87
  def format=(value)
72
88
  @formats << value
73
89
  end
74
90
 
75
91
  # Is the given format set?
92
+ # @param type ['bold', 'italic', 'underline', 'strikethrough']
93
+ # @return [Boolean]
76
94
  def formatted?(type)
77
95
  @formats.include?(type)
78
96
  end
@@ -83,6 +101,7 @@ module CSVPlusPlus
83
101
  end
84
102
 
85
103
  # Is the row forzen?
104
+ # @return [Boolean]
86
105
  def frozen?
87
106
  @frozen
88
107
  end
@@ -93,29 +112,37 @@ module CSVPlusPlus
93
112
  end
94
113
 
95
114
  # Is this a row-level modifier?
115
+ # @return [Boolean]
96
116
  def row_level?
97
117
  @row_level
98
118
  end
99
119
 
100
120
  # Is this a cell-level modifier?
121
+ # @return [Boolean]
101
122
  def cell_level?
102
123
  !@row_level
103
124
  end
104
125
 
105
126
  # Style of border
127
+ # @return [String]
106
128
  def borderstyle
107
129
  @borderstyle || 'solid'
108
130
  end
109
131
 
110
- # to_s
132
+ # @return [String]
111
133
  def to_s
112
134
  # TODO... I dunno, not sure how to manage this
113
- "Modifier(row_level: #{@row_level} align: #{@align} format: #{@formats} font_size: #{@font_size})"
135
+ "Modifier(row_level: #{@row_level} halign: #{@halign} valign: #{@valign} format: #{@formats} " \
136
+ "font_size: #{@font_size})"
114
137
  end
115
138
 
116
139
  # Create a new modifier instance, with all values defaulted from +other+
140
+ # @param other [Modifier]
117
141
  def take_defaults_from!(other)
118
- instance_variables.each do |property|
142
+ other.instance_variables.each do |property|
143
+ # don't propagate row-specific values
144
+ next if property == :@row_level
145
+
119
146
  value = other.instance_variable_get(property)
120
147
  instance_variable_set(property, value.clone)
121
148
  end