Class: Humidifier::Props::ListProp

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 = {}, subprop = nil) ⇒ ListProp

Returns a new instance of ListProp.



107
108
109
110
# File 'lib/humidifier/props.rb', line 107

def initialize(key, spec = {}, subprop = nil)
  super(key, spec)
  @subprop = subprop
end

Instance Attribute Details

#subpropObject (readonly)

Returns the value of attribute subprop.



105
106
107
# File 'lib/humidifier/props.rb', line 105

def subprop
  @subprop
end

Instance Method Details

#pretty_print(q) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
# File 'lib/humidifier/props.rb', line 112

def pretty_print(q)
  q.group do
    q.text("(#{name}=list")
    q.nest(2) do
      q.breakable
      q.pp(subprop)
    end
    q.breakable("")
    q.text(")")
  end
end

#to_cf(list) ⇒ Object



124
125
126
127
128
129
130
131
132
133
# File 'lib/humidifier/props.rb', line 124

def to_cf(list)
  cf_value =
    if list.respond_to?(:to_cf)
      list.to_cf
    else
      list.map { |value| subprop.to_cf(value).last }
    end

  [key, cf_value]
end

#valid?(list) ⇒ Boolean

Returns:

  • (Boolean)


135
136
137
138
139
# File 'lib/humidifier/props.rb', line 135

def valid?(list)
  return true if super(list)

  list.is_a?(Enumerable) && list.all? { |value| subprop.valid?(value) }
end