Class: Reportabull::Column

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Column.



7
8
9
10
11
12
# File 'lib/reportabull/column.rb', line 7

def initialize(name, options = {}, block = nil)
  @options = options
  options[:humanize_name] = true if options[:humanize_name].nil?
  @name = humanize_name(name, options[:humanize_name])
  @data = block || name.to_sym
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



5
6
7
# File 'lib/reportabull/column.rb', line 5

def data
  @data
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/reportabull/column.rb', line 5

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/reportabull/column.rb', line 5

def options
  @options
end

Instance Method Details

#humanize_name(name, humanize_name_option) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/reportabull/column.rb', line 14

def humanize_name(name, humanize_name_option)
  if humanize_name_option
    name.to_s.humanize
  else
    name.to_s
  end
end

#value(resource) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/reportabull/column.rb', line 22

def value(resource)
  case data
  when Symbol, String
    resource.send(data)
  when Proc
    resource.instance_exec(resource, &data)
  end
end