Class: Rspreadsheet::Border

Inherits:
Object
  • Object
show all
Defined in:
lib/rspreadsheet/cell_format.rb

Overview

represents one of the borders of a cell

initialization of style related nodes, if they do not exist collapse

Constructor Details

#initialize(cellformat, side) ⇒ Border

Returns a new instance of Border.



134
135
136
137
138
# File 'lib/rspreadsheet/cell_format.rb', line 134

def initialize(cellformat,side)
  @cellformat = cellformat
  @side = side.to_s
  raise "Wrong side of border object, can be top, bottom, left or right" unless ['left','right','top','bottom'].include? @side
end

Instance Method Details

#attribute_nameObject



140
# File 'lib/rspreadsheet/cell_format.rb', line 140

def attribute_name; "border-#{@side}" end

#cellnodeObject



139
# File 'lib/rspreadsheet/cell_format.rb', line 139

def cellnode; @cell.xmlnode end

#colorObject



147
# File 'lib/rspreadsheet/cell_format.rb', line 147

def color; get_border_string_part(3) end

#color=(value) ⇒ Object



144
# File 'lib/rspreadsheet/cell_format.rb', line 144

def color=(value); set_border_string_part(3, value) end

#deleteObject



148
149
150
# File 'lib/rspreadsheet/cell_format.rb', line 148

def delete
  @cellformat.set_cell_style_node_attribute(attribute_name, 'none')
end

#get_border_string_part(part) ⇒ Object



170
171
172
173
174
175
176
177
178
179
# File 'lib/rspreadsheet/cell_format.rb', line 170

def get_border_string_part(part)
  current_value = @cellformat.get_cell_style_node_attribute(attribute_name) || @cellformat.get_cell_style_node_attribute('border')
  if current_value.nil? or (current_value=='none')
    return nil
  else
    value_array = current_value.split(' ')  
    raise 'Strange border attribute value. Does not have 3 parts' unless value_array.length == 3
    return value_array[part-1]
  end
end

#get_value_stringObject



181
182
183
# File 'lib/rspreadsheet/cell_format.rb', line 181

def get_value_string
  @cellformat.get_cell_style_node_attribute(attribute_name)
end

#set_border_string_part(part, value) ⇒ Object

set parth-th part of string which represents the border. String looks like "0.06pt solid #00ee00" part is 1 for width, 2 for style or 3 for color



157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/rspreadsheet/cell_format.rb', line 157

def set_border_string_part(part,value)
  current_value = @cellformat.get_cell_style_node_attribute(attribute_name)
  
  if current_value.nil? or (current_value=='none')
    value_array = ['0.75pt', 'solid', '#000000']  # set default values
  else
    value_array = current_value.split(' ')  
  end
  raise 'Strange border attribute value. Does not have 3 parts' unless value_array.length == 3
  value_array[part-1]=value
  @cellformat.set_cell_style_node_attribute(attribute_name, value_array.join(' '))
end

#styleObject



146
# File 'lib/rspreadsheet/cell_format.rb', line 146

def style; get_border_string_part(2) end

#style=(value) ⇒ Object



143
# File 'lib/rspreadsheet/cell_format.rb', line 143

def style=(value); set_border_string_part(2, value.to_s) end

#widthObject



145
# File 'lib/rspreadsheet/cell_format.rb', line 145

def width; get_border_string_part(1).to_f end

#width=(value) ⇒ Object



142
# File 'lib/rspreadsheet/cell_format.rb', line 142

def width=(value); set_border_string_part(1, value) end