class Humidifier::Props::StructureProp

Attributes

subprops[R]

Public Class Methods

new(key, spec = {}, subprops = {}) click to toggle source
Calls superclass method Humidifier::Props::Prop::new
# File lib/humidifier/props.rb, line 185
def initialize(key, spec = {}, subprops = {})
  super(key, spec)
  @subprops = subprops
end

Public Instance Methods

pretty_print(q) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
Calls superclass method Humidifier::Props::Prop#valid?
# File lib/humidifier/props.rb, line 215
def valid?(struct)
  super(struct) || (struct.is_a?(Hash) && valid_struct?(struct))
end

Private Instance Methods

valid_struct?(struct) click to toggle source
# File lib/humidifier/props.rb, line 221
def valid_struct?(struct)
  struct.all? do |key, value|
    subprops.key?(key.to_s) && subprops[key.to_s].valid?(value)
  end
end