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 = {}, substructs = {}) ⇒ StructureProp
constructor
A new instance of StructureProp.
- #to_cf(struct) ⇒ Object
- #valid?(struct) ⇒ Boolean
Methods inherited from Prop
allow_type, allowed_types, #documentation, #required?, #update_type
Constructor Details
#initialize(key, spec = {}, substructs = {}) ⇒ StructureProp
Returns a new instance of StructureProp.
137 138 139 140 |
# File 'lib/humidifier/props.rb', line 137 def initialize(key, spec = {}, substructs = {}) super(key, spec) @subprops = subprops_from(substructs, spec['ItemType'] || spec['Type']) end |
Instance Attribute Details
#subprops ⇒ Object (readonly)
Returns the value of attribute subprops.
135 136 137 |
# File 'lib/humidifier/props.rb', line 135 def subprops @subprops end |
Instance Method Details
#to_cf(struct) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/humidifier/props.rb', line 142 def to_cf(struct) cf_value = if struct.respond_to?(:to_cf) struct.to_cf else struct.map do |subkey, subvalue| subprops[subkey.to_s].to_cf(subvalue) end.to_h end [key, cf_value] end |
#valid?(struct) ⇒ Boolean
155 156 157 |
# File 'lib/humidifier/props.rb', line 155 def valid?(struct) super(struct) || (struct.is_a?(Hash) && valid_struct?(struct)) end |