Class: QueryReport::ColumnModule::Column

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Column.



24
25
26
27
28
# File 'lib/query_report/column.rb', line 24

def initialize(report, column_name, options={}, block = nil)
  @report, @name, @options = report, column_name, options
  @type = @report.model_class.columns_hash[column_name.to_s].try(:type) || options[:type] || :string
  @data = block || column_name.to_sym
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



22
23
24
# File 'lib/query_report/column.rb', line 22

def data
  @data
end

#nameObject (readonly)

Returns the value of attribute name.



22
23
24
# File 'lib/query_report/column.rb', line 22

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



22
23
24
# File 'lib/query_report/column.rb', line 22

def options
  @options
end

#reportObject (readonly)

Returns the value of attribute report.



22
23
24
# File 'lib/query_report/column.rb', line 22

def report
  @report
end

#typeObject (readonly)

Returns the value of attribute type.



22
23
24
# File 'lib/query_report/column.rb', line 22

def type
  @type
end

Instance Method Details

#humanizeObject



34
35
36
# File 'lib/query_report/column.rb', line 34

def humanize
  @humanize ||= options[:as] || @report.model_class.human_attribute_name(name)
end

#only_on_web?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/query_report/column.rb', line 30

def only_on_web?
  @options[:only_on_web] == true
end

#value(record) ⇒ Object



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

def value(record)
  self.data.kind_of?(Symbol) ? record.send(self.name) : self.data.call(record)
end