class Pione::Lang::ParameterSet
ParameterSet
is a piece class for set of actual parameters.
Public Instance Methods
==(other)
click to toggle source
# File lib/pione/lang/parameters.rb, line 84 def ==(other) return false unless other.kind_of?(self.class) table == other.table end
delete_all(names)
click to toggle source
Return a parameter set excluding the names.
# File lib/pione/lang/parameters.rb, line 26 def delete_all(names) set(table: table.reject{|key, _| names.include?(key)}) end
eval(env)
click to toggle source
Evaluate the object with variable table.
# File lib/pione/lang/parameters.rb, line 11 def eval(env) set(table: Hash[*table.map{|key, val| [key, val.eval(env)]}.flatten(1)]) end
expand() { |set(table: inject(hash){|h, (k, v)| merge(k => v)})| ... }
click to toggle source
Expand parameter value sequences.
# File lib/pione/lang/parameters.rb, line 48 def expand if block_given? array = table.map do |k, v| [k, (v.respond_to?(:each) and v.distribution == :each) ? v.each : v] end find_atomic_composites(array, Hash.new) do |t| yield set(table: t.inject(Hash.new){|h, (k, v)| h.merge(k => v)}) end else Enumerator.new(self, :expand) end end
filter(names)
click to toggle source
Return a parameter set that match the names.
# File lib/pione/lang/parameters.rb, line 21 def filter(names) set(table: table.select{|key, _| names.include?(key)}) end
find_atomic_composites(array, table, &b)
click to toggle source
Find atomic parameters recursively.
# File lib/pione/lang/parameters.rb, line 62 def find_atomic_composites(array, table, &b) # end recursion return b.call(table) if array.empty? # find atomic composites key, enum = array.first tail = array.drop(1) loop do if enum.kind_of?(Enumerator) find_atomic_composites(tail, table.merge(key => enum.next), &b) else find_atomic_composites(tail, table.merge(key => enum), &b) raise StopIteration end end enum.rewind if enum.kind_of?(Enumerator) end
merge(other)
click to toggle source
Merge values of the other parameter set.
# File lib/pione/lang/parameters.rb, line 16 def merge(other) set(table: table.merge(other.table)) end
merge_default_values(rule_condition)
click to toggle source
Merge default values of the rule condition.
# File lib/pione/lang/parameters.rb, line 31 def merge_default_values(rule_condition) tbl = Hash.new rule_condition.param_definition.each do |key, param_definition| unless keys.include?(key) tbl[key] = param_definition.value end end set(table: table.merge(tbl)) end
textize()
click to toggle source
# File lib/pione/lang/parameters.rb, line 43 def textize "{" + table.keys.sort.map{|k| "%s:%s" % [k, table[k].textize]}.join(", ") + "}" end
to_json(*args)
click to toggle source
# File lib/pione/lang/parameters.rb, line 80 def to_json(*args) table.to_json(*args) end