class RubyXL::PrivateClass

Private Instance Methods

find_xf(workbook, xf) click to toggle source

This method checks to see if there is an equivalent xf that exists

# File lib/rubyXL/private_class.rb, line 38
def find_xf(workbook, xf)
  workbook.cell_xfs.each_with_index { |xfs, index| return index if xfs == xf }
  return nil
end
modify_alignment(workbook, style_index, is_horizontal, alignment) click to toggle source

is_horizontal is true when doing horizontal alignment, false when doing vertical alignment

# File lib/rubyXL/private_class.rb, line 69
def modify_alignment(workbook, style_index, is_horizontal, alignment)
  old_xf = workbook.cell_xfs[style_index]

  xf = old_xf.dup
  xf.alignment ||= RubyXL::Alignment.new

  if is_horizontal then xf.alignment.horizontal = alignment
  else                  xf.alignment.vertical   = alignment
  end
  xf.apply_alignment = true

  workbook.register_new_xf(xf, style_index)
end
modify_fill(workbook, style_index, rgb) click to toggle source

modifies fill array (copies, appends, adds color and solid attribute) then styles array (copies, appends)

# File lib/rubyXL/private_class.rb, line 59
def modify_fill(workbook, style_index, rgb)
  xf = workbook.cell_xfs[style_index]
  new_fill = RubyXL::Fill.new(:pattern_fill => 
               RubyXL::PatternFill.new(:pattern_type => 'solid', :fg_color => RubyXL::Color.new(:rgb => rgb)))
  new_xf = workbook.register_new_fill(new_fill, xf)
  workbook.register_new_xf(new_xf, style_index)
end
modify_text_wrap(workbook, style_index, wrapText = false) click to toggle source
# File lib/rubyXL/private_class.rb, line 83
def modify_text_wrap(workbook, style_index, wrapText = false)
  old_xf = workbook.cell_xfs[style_index]

  xf = old_xf.dup
  xf.alignment ||= RubyXL::Alignment.new
  xf.alignment.wrap_text = wrapText
  xf.apply_alignment = true

  workbook.register_new_xf(xf, style_index)
end
modify_xf(workbook, xf) click to toggle source

Determines if xf exists If yes, return id of existing xf If no, appends xf to xf array

# File lib/rubyXL/private_class.rb, line 46
def modify_xf(workbook, xf)
  existing_xf_id = find_xf(workbook, xf)
  if !existing_xf_id.nil?
    xf_id = existing_xf_id
  else
    xf.apply_font = true
    xf_id = workbook.cell_xfs.size - 1
  end
  return xf_id
end
validate_border(weight) click to toggle source
# File lib/rubyXL/private_class.rb, line 24
def validate_border(weight)
  if weight.to_s == '' || weight == 'thin' || weight == 'thick' || weight == 'hairline' || weight == 'medium'
    return true
  end
  raise 'Border weights must only be "hairline", "thin", "medium", or "thick"'
end
validate_horizontal_alignment(alignment) click to toggle source

validate and modify methods

# File lib/rubyXL/private_class.rb, line 6
def validate_horizontal_alignment(alignment)
  if alignment.to_s == '' || alignment == 'center' || alignment == 'distributed' || alignment == 'justify' || alignment == 'left' || alignment == 'right'
    return true
  end
  raise 'Only center, distributed, justify, left, and right are valid horizontal alignments'
end
validate_nonnegative(row_or_col) click to toggle source
# File lib/rubyXL/private_class.rb, line 31
def validate_nonnegative(row_or_col)
  if row_or_col < 0
    raise 'Row and Column arguments must be nonnegative'
  end
end
validate_text_wrap(wrap) click to toggle source
# File lib/rubyXL/private_class.rb, line 20
def validate_text_wrap(wrap)
  raise 'Only true or false are valid wraps' unless wrap.is_a?(FalseClass) || wrap.is_a?(TrueClass)
end
validate_vertical_alignment(alignment) click to toggle source
# File lib/rubyXL/private_class.rb, line 13
def validate_vertical_alignment(alignment)
  if alignment.to_s == '' || alignment == 'center' || alignment == 'distributed' || alignment == 'justify' || alignment == 'top' || alignment == 'bottom'
    return true
  end
  raise 'Only center, distributed, justify, top, and bottom are valid vertical alignments'
end