Class: Rspreadsheet::Border

Inherits:
Object
  • Object
show all
Defined in:
lib/rspreadsheet/cell.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.



343
344
345
346
347
# File 'lib/rspreadsheet/cell.rb', line 343

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



349
# File 'lib/rspreadsheet/cell.rb', line 349

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

#cellnodeObject



348
# File 'lib/rspreadsheet/cell.rb', line 348

def cellnode; @cell.xmlnode end

#colorObject



356
# File 'lib/rspreadsheet/cell.rb', line 356

def color; get_border_string_part(3) end

#color=(value) ⇒ Object



353
# File 'lib/rspreadsheet/cell.rb', line 353

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

#deleteObject



357
358
359
# File 'lib/rspreadsheet/cell.rb', line 357

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

#get_border_string_part(part) ⇒ Object



379
380
381
382
383
384
385
386
387
388
# File 'lib/rspreadsheet/cell.rb', line 379

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



390
391
392
# File 'lib/rspreadsheet/cell.rb', line 390

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



366
367
368
369
370
371
372
373
374
375
376
377
# File 'lib/rspreadsheet/cell.rb', line 366

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



355
# File 'lib/rspreadsheet/cell.rb', line 355

def style; get_border_string_part(2) end

#style=(value) ⇒ Object



352
# File 'lib/rspreadsheet/cell.rb', line 352

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

#widthObject



354
# File 'lib/rspreadsheet/cell.rb', line 354

def width; get_border_string_part(1).to_f end

#width=(value) ⇒ Object



351
# File 'lib/rspreadsheet/cell.rb', line 351

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