Class: Noventius::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/noventius/column.rb

Constant Summary collapse

TYPES =
%i(string integer float datetime date)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type, options = {}) ⇒ Column

rubocop:disable Metrics/CyclomaticComplexity



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/noventius/column.rb', line 10

def initialize(name, type, options = {})
  fail ArgumentError, "ColumnType: [#{type}] not yet implemented." unless TYPES.include?(type.to_sym)

  @name = name.to_sym
  @type = type.to_sym
  @label = options.delete(:label) || @name.to_s
  @label = instance_exec(&@label) if @label.is_a?(Proc)
  @default_value = options[:default_value] || default_value_for_type
  @value = options[:value] || default_value_block(@name, @default_value)
  @options = options
  @children = options[:children] || []
end

Instance Attribute Details

#labelObject (readonly)

Returns the value of attribute label.



7
8
9
# File 'lib/noventius/column.rb', line 7

def label
  @label
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/noventius/column.rb', line 7

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



7
8
9
# File 'lib/noventius/column.rb', line 7

def type
  @type
end

Instance Method Details

#depthObject



38
39
40
# File 'lib/noventius/column.rb', line 38

def depth
  1
end

#html_optionsObject

rubocop:enable Metrics/CyclomaticComplexity



24
25
26
# File 'lib/noventius/column.rb', line 24

def html_options
  @options[:html_options] || {}
end

#value(report, row) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/noventius/column.rb', line 28

def value(report, row)
  if @value.is_a?(Proc)
    report.instance_exec(row, &@value)
  elsif @value.is_a?(Symbol)
    report.public_send(@value, row)
  else
    @value
  end
end