Class: Humidifier::Props::ListProp

Inherits:
Prop
  • Object
show all
Defined in:
lib/humidifier/props.rb

Constant Summary

Constants inherited from Prop

Prop::WHITELIST

Instance Attribute Summary collapse

Attributes inherited from Prop

#key, #name, #spec

Instance Method Summary collapse

Methods inherited from Prop

allow_type, allowed_types, #documentation, #required?, #update_type

Constructor Details

#initialize(key, spec = {}, substructs = {}) ⇒ ListProp

Returns a new instance of ListProp.


83
84
85
86
# File 'lib/humidifier/props.rb', line 83

def initialize(key, spec = {}, substructs = {})
  super(key, spec)
  @subprop = Props.singular_from(key, spec, substructs)
end

Instance Attribute Details

#subpropObject (readonly)

Returns the value of attribute subprop


81
82
83
# File 'lib/humidifier/props.rb', line 81

def subprop
  @subprop
end

Instance Method Details

#to_cf(list) ⇒ Object


88
89
90
91
92
93
94
95
96
97
# File 'lib/humidifier/props.rb', line 88

def to_cf(list)
  cf_value =
    if list.respond_to?(:to_cf)
      list.to_cf
    else
      list.map { |value| subprop.to_cf(value).last }
    end

  [key, cf_value]
end

#valid?(list) ⇒ Boolean

Returns:

  • (Boolean)

99
100
101
102
103
# File 'lib/humidifier/props.rb', line 99

def valid?(list)
  return true if super(list)

  list.is_a?(Enumerable) && list.all? { |value| subprop.valid?(value) }
end