Class: Rspreadsheet::Border

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

Overview

represents one of the borders of a cell

other routines collapse

Constructor Details

#initialize(cellformat, side) ⇒ Border

Returns a new instance of Border.



155
156
157
158
159
# File 'lib/rspreadsheet/cell_format.rb', line 155

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



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

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

#cellnodeObject



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

def cellnode; @cell.xmlnode end

#colorObject



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

def color; get_border_string_part(3) end

#color=(value) ⇒ Object



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

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

#deleteObject



169
170
171
# File 'lib/rspreadsheet/cell_format.rb', line 169

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

#get_border_stringObject



190
191
192
193
194
# File 'lib/rspreadsheet/cell_format.rb', line 190

def get_border_string
  result = @cellformat.get_cell_style_node_attribute(attribute_name) || @cellformat.get_cell_style_node_attribute('border')
  result = nil if result=='none'
  result
end

#get_border_string_part(part) ⇒ Object



196
197
198
199
200
201
202
203
# File 'lib/rspreadsheet/cell_format.rb', line 196

def get_border_string_part(part)
  border_string = get_border_string
  return nil if border_string.nil?
    
  value_array = border_string.split(' ')  
  raise 'Strange border attribute value. Does not have 3 parts' unless value_array.length == 3
  return value_array[part-1]
end

#set_border_string_part(part, value) ⇒ Object

set part-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



177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/rspreadsheet/cell_format.rb', line 177

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



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

def style; get_border_string_part(2) end

#style=(value) ⇒ Object



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

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

#widthObject



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

def width; get_border_string_part(1).to_f end

#width=(value) ⇒ Object



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

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