class PropList
Public Class Methods
new(propclass=PropSet)
click to toggle source
# File lib/proplist.rb, line 86 def initialize(propclass=PropSet) @propclass = propclass @data = {} end
Public Instance Methods
[](kvs)
click to toggle source
TODO: have the node say “parameter[]” when it wants a singular results with possibly a warning or even exception when more than one matches, vs “parameters[]” which always gives an array, even if only one or zero matches…
# File lib/proplist.rb, line 94 def [](kvs) kvs = {name: kvs} unless Hash === kvs res = @data.values kvs.each{|k,v| res = res.select{|prop| prop.send(k) == v}} case res.size when 0 then nil when 1 then res[0] else res end end
add(name, *opts)
click to toggle source
# File lib/proplist.rb, line 117 def add(name, *opts) name = name.to_sym if @data[name] && opts.present? then @data[name].merge_opts(opts) elsif !@data[name] then @data[name] = @propclass.new(opts, name: name) end @data[name] end
add_name_opts(name_and_opts)
click to toggle source
TODO: add-override separate from add-unique - the first used in inheritance, for example when currying parameters, and the latter used when composing many together that might normally have name conflicts.
# File lib/proplist.rb, line 114 def add_name_opts(name_and_opts) name = name_and_opts.shift; add(name, name_and_opts) end
Also aliased as: <<
dup()
click to toggle source
# File lib/proplist.rb, line 106 def dup() Marshal.load(Marshal.dump(self)) end
include?(k)
click to toggle source
TODO: method_missing
revolves around ‘by_xxxx` - gives a hash indexed by the stated propset-value
if no `by_` then it is assumed to be the index into ANY of the propset-values that has a symbol or string as the value. If the by_xxxx were chainable, it could be a method_missing equivalent of the [] search method... (probably not important)
Calls superclass method
# File lib/proplist.rb, line 140 def include?(k) super(k.to_sym) end
Also aliased as: includes?
method_missing(m, *a, &b)
click to toggle source
Calls superclass method
# File lib/proplist.rb, line 128 def method_missing(m, *a, &b) return @data[m.to_sym] if @data.has_key?(m.to_sym) return @data.send(m, *a, &b) if @data.respond_to?(m) return @data.has_key?(m[4..-2].to_sym) if m[/has_.+\?/] super end
realize(name, value)
click to toggle source
# File lib/proplist.rb, line 108 def realize(name, value) add(name).tap{|pset| pset.realize(value)} end
Also aliased as: []=
respond_to?(m, inc_all=false)
click to toggle source
# File lib/proplist.rb, line 124 def respond_to?(m, inc_all=false) @data.has_key?(m.to_sym) || @data.respond_to?(m, inc_all) || !!m[/has_.+\?/] end