Class: Humidifier::Props::ListProp
Constant Summary
Constants inherited from Prop
Instance Attribute Summary collapse
-
#subprop ⇒ Object
readonly
Returns the value of attribute subprop.
Attributes inherited from Prop
Instance Method Summary collapse
-
#initialize(key, spec = {}, subprop = nil) ⇒ ListProp
constructor
A new instance of ListProp.
- #pretty_print(q) ⇒ Object
- #to_cf(list) ⇒ Object
- #valid?(list) ⇒ Boolean
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
#subprop ⇒ Object (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
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 |