Class: NestedStruct::Field
- Inherits:
-
Object
- Object
- NestedStruct::Field
- Defined in:
- lib/nested_struct/field.rb
Instance Attribute Summary collapse
-
#coercer ⇒ Object
readonly
Returns the value of attribute coercer.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #coerced? ⇒ Boolean
-
#initialize(name, coercer_expression = nil) ⇒ Field
constructor
A new instance of Field.
- #with(value) ⇒ Object
Constructor Details
#initialize(name, coercer_expression = nil) ⇒ Field
Returns a new instance of Field.
5 6 7 8 |
# File 'lib/nested_struct/field.rb', line 5 def initialize(name, coercer_expression = nil) @name = name @coercer = Coercer.new(coercer_expression) if coercer_expression end |
Instance Attribute Details
#coercer ⇒ Object (readonly)
Returns the value of attribute coercer.
3 4 5 |
# File 'lib/nested_struct/field.rb', line 3 def coercer @coercer end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/nested_struct/field.rb', line 3 def name @name end |
Instance Method Details
#coerced? ⇒ Boolean
16 17 18 |
# File 'lib/nested_struct/field.rb', line 16 def coerced? !coercer.nil? end |
#with(value) ⇒ Object
10 11 12 13 14 |
# File 'lib/nested_struct/field.rb', line 10 def with(value) return value if value.nil? return value if !coerced? coercer.coerce(value) end |