Class: Humidifier::Props::MapProp
Constant Summary
Constants inherited from Prop
Instance Attribute Summary collapse
-
#subprop ⇒ Object
readonly
Returns the value of attribute subprop.
Attributes inherited from Prop
Instance Method Summary collapse
-
#initialize(key, spec = {}, substructs = {}) ⇒ MapProp
constructor
A new instance of MapProp.
- #to_cf(map) ⇒ Object
- #valid?(map) ⇒ Boolean
Methods inherited from Prop
allow_type, allowed_types, #documentation, #required?, #update_type
Constructor Details
#initialize(key, spec = {}, substructs = {}) ⇒ MapProp
Returns a new instance of MapProp.
109 110 111 112 |
# File 'lib/humidifier/props.rb', line 109 def initialize(key, spec = {}, substructs = {}) super(key, spec) @subprop = Props.singular_from(key, spec, substructs) end |
Instance Attribute Details
#subprop ⇒ Object (readonly)
Returns the value of attribute subprop.
107 108 109 |
# File 'lib/humidifier/props.rb', line 107 def subprop @subprop end |
Instance Method Details
#to_cf(map) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/humidifier/props.rb', line 114 def to_cf(map) cf_value = if map.respond_to?(:to_cf) map.to_cf else map.map do |subkey, subvalue| [subkey, subprop.to_cf(subvalue).last] end.to_h end [key, cf_value] end |
#valid?(map) ⇒ Boolean
127 128 129 130 131 |
# File 'lib/humidifier/props.rb', line 127 def valid?(map) return true if super(map) map.is_a?(Hash) && map.values.all? { |value| subprop.valid?(value) } end |