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) ⇒ Field

Returns a new instance of Field.



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

def initialize(report, name, processor)
  @report = report
  @name = name
  @processor = processor
end

Instance Attribute Details

#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) ⇒ Object



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

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

Instance Method Details

#process(model) ⇒ Object



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

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