Class: MagicReport::Report::Builder::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/magic_report/report/builder/field.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(report, name, processor, options) ⇒ Field

Returns a new instance of Field.



13
14
15
16
17
18
# File 'lib/magic_report/report/builder/field.rb', line 13

def initialize(report, name, processor, options)
  @report = report
  @name = name
  @processor = processor
  @is_primary = options.fetch(:primary, false)
end

Instance Attribute Details

#is_primaryObject (readonly)

Returns the value of attribute is_primary.



11
12
13
# File 'lib/magic_report/report/builder/field.rb', line 11

def is_primary
  @is_primary
end

#nameObject (readonly)

Returns the value of attribute name.



11
12
13
# File 'lib/magic_report/report/builder/field.rb', line 11

def name
  @name
end

#processorObject (readonly)

Returns the value of attribute processor.



11
12
13
# File 'lib/magic_report/report/builder/field.rb', line 11

def processor
  @processor
end

#reportObject (readonly)

Returns the value of attribute report.



11
12
13
# File 'lib/magic_report/report/builder/field.rb', line 11

def report
  @report
end

Class Method Details

.build(report, name, processor, options) ⇒ Object



7
8
9
# File 'lib/magic_report/report/builder/field.rb', line 7

def self.build(report, name, processor, options)
  new(report, name, processor, options)
end

Instance Method Details

#process(model) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/magic_report/report/builder/field.rb', line 20

def process(model)
  value = extract_value(model)

  if processor.is_a? Proc
    processor.call(model, value)
  elsif processor.is_a? Symbol
    # Refactor
    report.new(nil).send(processor, model, value)
  else
    value
  end
end