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 = {}, subprop = nil) ⇒ MapProp
constructor
A new instance of MapProp.
- #pretty_print(q) ⇒ Object
- #to_cf(map) ⇒ Object
- #valid?(map) ⇒ Boolean
Methods inherited from Prop
allow_type, allowed_types, #documentation, #required?, #update_type
Constructor Details
#initialize(key, spec = {}, subprop = nil) ⇒ MapProp
Returns a new instance of MapProp.
145 146 147 148 |
# File 'lib/humidifier/props.rb', line 145 def initialize(key, spec = {}, subprop = nil) super(key, spec) @subprop = subprop end |
Instance Attribute Details
#subprop ⇒ Object (readonly)
Returns the value of attribute subprop.
143 144 145 |
# File 'lib/humidifier/props.rb', line 143 def subprop @subprop end |
Instance Method Details
#pretty_print(q) ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/humidifier/props.rb', line 150 def pretty_print(q) q.group do q.text("(#{name}=map") q.nest(2) do q.breakable q.pp(subprop) end q.breakable("") q.text(")") end end |
#to_cf(map) ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/humidifier/props.rb', line 162 def to_cf(map) cf_value = if map.respond_to?(:to_cf) map.to_cf else map.to_h do |subkey, subvalue| [subkey, subprop.to_cf(subvalue).last] end end [key, cf_value] end |
#valid?(map) ⇒ Boolean
175 176 177 178 179 |
# File 'lib/humidifier/props.rb', line 175 def valid?(map) return true if super(map) map.is_a?(Hash) && map.values.all? { |value| subprop.valid?(value) } end |