Class: Objectifier::ArrayValue
- Inherits:
-
Object
- Object
- Objectifier::ArrayValue
- Defined in:
- lib/objectifier/array_value.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #call(parameters) ⇒ Object
-
#initialize(name, args) ⇒ ArrayValue
constructor
A new instance of ArrayValue.
- #required? ⇒ Boolean
Constructor Details
#initialize(name, args) ⇒ ArrayValue
Returns a new instance of ArrayValue.
7 8 9 10 11 12 13 14 |
# File 'lib/objectifier/array_value.rb', line 7 def initialize(name, args) raise ArgumentError, "name required" if name.nil? raise ArgumentError, "type required" unless args[:type] @name = name.to_s @type = args[:type] @required = args.fetch(:required, true) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/objectifier/array_value.rb', line 5 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
5 6 7 |
# File 'lib/objectifier/array_value.rb', line 5 def type @type end |
Instance Method Details
#call(parameters) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/objectifier/array_value.rb', line 20 def call(parameters) if @required && !key_present(parameters) ErrorResult.err(@name, "required field missing") elsif key_present(parameters) transform(key_value(parameters)) else SuccessResult.new(@name) end end |
#required? ⇒ Boolean
16 17 18 |
# File 'lib/objectifier/array_value.rb', line 16 def required? @required end |