Class: TableData::Presenter

Inherits:
Object
  • Object
show all
Defined in:
lib/tabledata/presenter.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table, options) ⇒ Presenter

Returns a new instance of Presenter.



26
27
28
29
# File 'lib/tabledata/presenter.rb', line 26

def initialize(table, options)
  @table   = table
  @options = options
end

Instance Attribute Details

#tableObject (readonly)

Returns the value of attribute table.



24
25
26
# File 'lib/tabledata/presenter.rb', line 24

def table
  @table
end

Class Method Details

.present(table, format, options) ⇒ Object

Raises:

  • (ArgumentError)


15
16
17
18
19
20
21
22
# File 'lib/tabledata/presenter.rb', line 15

def self.present(table, format, options)
  code, constant, default_options = *@presenters[format]
  raise ArgumentError, "Unknown format #{format.inspect}" unless code
  require code
  klass = constant.inject(Object) { |source, current| source.const_get(current) }

  klass.new(table, options ? default_options.merge(options) : default_options.dup)
end

Instance Method Details

#write(path, options = nil) ⇒ Object



31
32
33
# File 'lib/tabledata/presenter.rb', line 31

def write(path, options=nil)
  File.write(path, string, encoding: 'utf-8')
end