Class: Humidifier::Props::StructureProp

Inherits:
Prop
  • Object
show all
Defined in:
lib/humidifier/props.rb

Constant Summary

Constants inherited from Prop

Prop::WHITELIST

Instance Attribute Summary collapse

Attributes inherited from Prop

#key, #name, #spec

Instance Method Summary collapse

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

#subpropsObject (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

Returns:

  • (Boolean)


155
156
157
# File 'lib/humidifier/props.rb', line 155

def valid?(struct)
  super(struct) || (struct.is_a?(Hash) && valid_struct?(struct))
end