Class: Mabmapper::Engine::Field
- Inherits:
-
Object
- Object
- Mabmapper::Engine::Field
- Defined in:
- lib/mabmapper/engine.rb
Overview
Instance Attribute Summary collapse
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
-
#engine ⇒ Object
Returns the value of attribute engine.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
-
#initialize(name, &block) ⇒ Field
constructor
A new instance of Field.
- #merge(value1, value2, options = {delimiter: ' ', wrap: nil}) ⇒ Object
- #ref(field_name) ⇒ Object
- #wrap(value, pattern) ⇒ Object
Constructor Details
#initialize(name, &block) ⇒ Field
Returns a new instance of Field.
81 82 83 84 85 |
# File 'lib/mabmapper/engine.rb', line 81 def initialize(name, &block) @name = name.to_s @proc = block @engine = eval("self", block.binding) end |
Instance Attribute Details
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
87 88 89 |
# File 'lib/mabmapper/engine.rb', line 87 def doc @doc end |
#engine ⇒ Object
Returns the value of attribute engine.
79 80 81 |
# File 'lib/mabmapper/engine.rb', line 79 def engine @engine end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
87 88 89 |
# File 'lib/mabmapper/engine.rb', line 87 def name @name end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
87 88 89 |
# File 'lib/mabmapper/engine.rb', line 87 def result @result end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
87 88 89 |
# File 'lib/mabmapper/engine.rb', line 87 def source @source end |
Instance Method Details
#merge(value1, value2, options = {delimiter: ' ', wrap: nil}) ⇒ Object
95 96 97 98 99 100 |
# File 'lib/mabmapper/engine.rb', line 95 def merge(value1, value2, = {delimiter: ' ', wrap: nil}) v1 = [value1].map(&:presence).compact.join([:delimiter]) v2 = [value2].map(&:presence).compact.join([:delimiter]) v2 = wrap(v2, [:wrap]) if v2.present? and [:wrap].present? [v1, v2].map(&:presence).compact.join([:delimiter]) end |
#ref(field_name) ⇒ Object
89 90 91 92 93 |
# File 'lib/mabmapper/engine.rb', line 89 def ref(field_name) field = @engine.fields.find{ |f| f.name == field_name.to_s } raise "No such field #{field_name} in section #{section_name}" if field.blank? field.result end |
#wrap(value, pattern) ⇒ Object
102 103 104 |
# File 'lib/mabmapper/engine.rb', line 102 def wrap(value, pattern) pattern.gsub("@", value) end |