Class: Humidifier::Props::StructureProp
- Defined in:
- lib/humidifier/props.rb
Constant Summary
Constants inherited from Prop
Instance Attribute Summary collapse
-
#subprops ⇒ Object
readonly
Returns the value of attribute subprops.
Attributes inherited from Prop
Instance Method Summary collapse
-
#initialize(key, spec = {}, subprops = {}) ⇒ StructureProp
constructor
A new instance of StructureProp.
- #pretty_print(q) ⇒ Object
- #to_cf(struct) ⇒ Object
- #valid?(struct) ⇒ Boolean
Methods inherited from Prop
allow_type, allowed_types, #documentation, #required?, #update_type
Constructor Details
#initialize(key, spec = {}, subprops = {}) ⇒ StructureProp
Returns a new instance of StructureProp.
185 186 187 188 |
# File 'lib/humidifier/props.rb', line 185 def initialize(key, spec = {}, subprops = {}) super(key, spec) @subprops = subprops end |
Instance Attribute Details
#subprops ⇒ Object (readonly)
Returns the value of attribute subprops.
183 184 185 |
# File 'lib/humidifier/props.rb', line 183 def subprops @subprops end |
Instance Method Details
#pretty_print(q) ⇒ Object
190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/humidifier/props.rb', line 190 def pretty_print(q) q.group do q.text("(#{name}=structure") q.nest(2) do q.breakable q.seplist(subprops.values) { |subprop| q.pp(subprop) } end q.breakable("") q.text(")") end end |
#to_cf(struct) ⇒ Object
202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/humidifier/props.rb', line 202 def to_cf(struct) cf_value = if struct.respond_to?(:to_cf) struct.to_cf else struct.to_h do |subkey, subvalue| subprops[subkey.to_s].to_cf(subvalue) end end [key, cf_value] end |
#valid?(struct) ⇒ Boolean
215 216 217 |
# File 'lib/humidifier/props.rb', line 215 def valid?(struct) super(struct) || (struct.is_a?(Hash) && valid_struct?(struct)) end |