Method: Axlsx::Styles#parse_border_options

Defined in:
lib/axlsx/stylesheet/styles.rb

#parse_border_options(options = {}) ⇒ Border|Integer

Note:

noop if :border is not specified in options

parses Style#add_style options for borders.

Examples:

#apply a thick red border to the top and bottom
{ :border => { :style => :thick, :color => "FFFF0000", :edges => [:top, :bottom] }

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • A (Hash|Integer)

    border style definition hash or the index of an existing border. Border style definition hashes must include :style and color: key-value entries and may include an :edges entry that references an array of symbols identifying which border edges you wish to apply the style or any other valid Border initializer options. If the :edges entity is not provided the style is applied to all edges of cells that reference this style.

Returns:



306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
# File 'lib/axlsx/stylesheet/styles.rb', line 306

def parse_border_options(options={})
  return unless options[:border]
  b_opts = options[:border]
  if b_opts.is_a?(Hash)
    raise ArgumentError, (ERR_INVALID_BORDER_OPTIONS % b_opts) unless b_opts.values_at(:style, :color).size == 2
    border = Border.new b_opts
    (b_opts[:edges] || [:left, :right, :top, :bottom]).each do |edge|
      b_options = { :name => edge, :style => b_opts[:style], :color => Color.new(:rgb => b_opts[:color]) }
      border.prs << BorderPr.new(b_options)
    end
    options[:type] == :dxf ? border : borders << border
  elsif b_opts.is_a? Integer
    raise ArgumentError, (ERR_INVALID_BORDER_ID % b_opts) unless b_opts < borders.size
    if options[:type] == :dxf
      borders[b_opts].clone
    else
      border = b_opts
    end
  end
end