Class: Objectifier::ArrayValue

Inherits:
Object
  • Object
show all
Defined in:
lib/objectifier/array_value.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, args) ⇒ ArrayValue

Returns a new instance of ArrayValue.

Raises:

  • (ArgumentError)


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

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/objectifier/array_value.rb', line 5

def name
  @name
end

#typeObject (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

Returns:

  • (Boolean)


16
17
18
# File 'lib/objectifier/array_value.rb', line 16

def required?
  @required
end