module AxlsxStyler::Cell

Attributes

raw_style[RW]

Public Instance Methods

add_style(style) click to toggle source
# File lib/axlsx_styler/axlsx_cell.rb, line 7
def add_style(style)
  self.raw_style ||= {}
  add_to_raw_style(style)
  workbook.add_styled_cell self
end

Private Instance Methods

add_to_raw_style(style) click to toggle source
# File lib/axlsx_styler/axlsx_cell.rb, line 19
def add_to_raw_style(style)
  # using deep_merge from active_support:
  # with regular Hash#merge adding borders fails miserably
  new_style = raw_style.deep_merge style

  if with_border?(raw_style) && with_border?(style)
    border_at = (raw_style[:border][:edges] || all_edges) + (style[:border][:edges] || all_edges)
    new_style[:border][:edges] = border_at.uniq.sort
  elsif with_border?(style)
    new_style[:border] = style[:border]
  end

  self.raw_style = new_style
end
all_edges() click to toggle source
# File lib/axlsx_styler/axlsx_cell.rb, line 38
def all_edges
  [:top, :right, :bottom, :left]
end
with_border?(style) click to toggle source
# File lib/axlsx_styler/axlsx_cell.rb, line 34
def with_border?(style)
  !style[:border].nil?
end
workbook() click to toggle source
# File lib/axlsx_styler/axlsx_cell.rb, line 15
def workbook
  row.worksheet.workbook
end