class Humidifier::Props::StructureProp
Attributes
subprops[R]
Public Class Methods
new(key, spec = {}, substructs = {})
click to toggle source
Calls superclass method
Humidifier::Props::Prop::new
# File lib/humidifier/props.rb, line 137 def initialize(key, spec = {}, substructs = {}) super(key, spec) @subprops = subprops_from(substructs, spec['ItemType'] || spec['Type']) end
Public Instance Methods
to_cf(struct)
click to toggle source
# 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)
click to toggle source
Calls superclass method
Humidifier::Props::Prop#valid?
# File lib/humidifier/props.rb, line 155 def valid?(struct) super(struct) || (struct.is_a?(Hash) && valid_struct?(struct)) end
Private Instance Methods
subprops_from(substructs, type)
click to toggle source
# File lib/humidifier/props.rb, line 161 def subprops_from(substructs, type) subprop_names = substructs.fetch(type, {}).fetch('Properties', {}) subprop_names.each_with_object({}) do |(key, config), subprops| subprops[key.underscore] = if config['ItemType'] == type self else Props.from(key, config, substructs) end end end
valid_struct?(struct)
click to toggle source
# File lib/humidifier/props.rb, line 174 def valid_struct?(struct) struct.all? do |key, value| subprops.key?(key.to_s) && subprops[key.to_s].valid?(value) end end