Sha256: 801bc04649bcc35ea0324ec84f76c44524419c3188e294650f3250b39bae2d0e
Contents?: true
Size: 1.45 KB
Versions: 3
Compression:
Stored size: 1.45 KB
Contents
class BorderCreator attr_reader :worksheet, :cells, :edges def initialize(worksheet, cells, edges) @worksheet = worksheet @cells = cells @edges = edges end def draw selected_edges(edges).each { |edge| add_border(edge) } end private def selected_edges(edges) all_edges = [:top, :right, :bottom, :left] if edges == :all all_edges elsif edges.is_a?(Array) && edges - all_edges == [] edges.uniq else [] end end def add_border(position) style = { border: { style: :thin, color: '000000', edges: [position.to_sym] } } worksheet.add_style border_cells[position.to_sym], style # add_style border_cells(cell_ref)[position.to_sym], style end def border_cells # example range "B2:D5" { top: "#{first_cell}:#{last_col}#{first_row}", # "B2:D2" right: "#{last_col}#{first_row}:#{last_cell}", # "D2:D5" bottom: "#{first_col}#{last_row}:#{last_cell}", # "B5:D5" left: "#{first_cell}:#{first_col}#{last_row}" # "B2:B5" } end def first_cell @first_cell ||= cells.first.r end def last_cell @last_cell ||= cells.last.r end def first_row @first_row ||= first_cell.scan(/\d+/).first end def first_col @first_col ||= first_cell.scan(/\D+/).first end def last_row @last_row ||= last_cell.scan(/\d+/).first end def last_col @last_col ||= last_cell.scan(/\D+/).first end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
axlsx_styler-0.1.2 | lib/axlsx_styler/border_creator.rb |
axlsx_styler-0.1.1 | lib/axlsx_styler/border_creator.rb |
axlsx_styler-0.1.0 | lib/axlsx_styler/border_creator.rb |