Class: Bmg::Writer::Xlsx

Inherits:
Object
  • Object
show all
Includes:
Bmg::Writer
Defined in:
lib/bmg/writer/xlsx.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xlsx_options, output_preferences = nil) ⇒ Xlsx

Returns a new instance of Xlsx.



9
10
11
12
13
# File 'lib/bmg/writer/xlsx.rb', line 9

def initialize(xlsx_options, output_preferences = nil)
  require 'write_xlsx'
  @xlsx_options = DEFAULT_OPTIONS.merge(xlsx_options)
  @output_preferences = OutputPreferences.dress(output_preferences)
end

Instance Attribute Details

#output_preferencesObject (readonly)

Returns the value of attribute output_preferences.



14
15
16
# File 'lib/bmg/writer/xlsx.rb', line 14

def output_preferences
  @output_preferences
end

#xlsx_optionsObject (readonly)

Returns the value of attribute xlsx_options.



14
15
16
# File 'lib/bmg/writer/xlsx.rb', line 14

def xlsx_options
  @xlsx_options
end

Class Method Details

.to_xlsx(database, path) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/bmg/writer/xlsx.rb', line 20

def self.to_xlsx(database, path)
  require 'write_xlsx'
  workbook = WriteXLSX.new(path)
  database.each_relation_pair do |name, rel|
    worksheet = workbook.add_worksheet(name)
    rel.to_xlsx({
      workbook: workbook,
      worksheet: worksheet,
    })
  end
  workbook.close
end

Instance Method Details

#call(relation, path) ⇒ Object



16
17
18
# File 'lib/bmg/writer/xlsx.rb', line 16

def call(relation, path)
  dup._call(relation, path)
end