Class: MagicReport::Report::Builder::Field
- Inherits:
-
Object
- Object
- MagicReport::Report::Builder::Field
- Defined in:
- lib/magic_report/report/builder/field.rb
Instance Attribute Summary collapse
-
#is_primary ⇒ Object
readonly
Returns the value of attribute is_primary.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#processor ⇒ Object
readonly
Returns the value of attribute processor.
-
#report ⇒ Object
readonly
Returns the value of attribute report.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(report, name, processor, options) ⇒ Field
constructor
A new instance of Field.
- #process(model) ⇒ Object
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, ) @report = report @name = name @processor = processor @is_primary = .fetch(:primary, false) end |
Instance Attribute Details
#is_primary ⇒ Object (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 |
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/magic_report/report/builder/field.rb', line 11 def name @name end |
#processor ⇒ Object (readonly)
Returns the value of attribute processor.
11 12 13 |
# File 'lib/magic_report/report/builder/field.rb', line 11 def processor @processor end |
#report ⇒ Object (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, ) new(report, name, processor, ) 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 |