Class: PgVerify::Model::VariableSet
- Inherits:
-
Object
- Object
- PgVerify::Model::VariableSet
- Defined in:
- lib/pg-verify/model/variable_set.rb
Instance Attribute Summary collapse
-
#map(&blk) ⇒ Object
Returns the value of attribute map.
Instance Method Summary collapse
- #+(varset) ⇒ Object
- #<<(var) ⇒ Object
- #[](name) ⇒ Object
- #constname?(name) ⇒ Boolean
- #empty? ⇒ Boolean
- #get(*names) ⇒ Object
- #include?(name_or_var) ⇒ Boolean
-
#initialize(*variables) ⇒ VariableSet
constructor
A new instance of VariableSet.
- #names ⇒ Object
- #select_by_owner(owner) ⇒ Object
- #to_a ⇒ Object
- #to_s ⇒ Object
-
#values ⇒ Object
Returns all possible values of variables in this set as an array.
- #varname?(name) ⇒ Boolean
Constructor Details
#initialize(*variables) ⇒ VariableSet
Returns a new instance of VariableSet.
9 10 11 12 |
# File 'lib/pg-verify/model/variable_set.rb', line 9 def initialize(*variables) @map = {} self << variables end |
Instance Attribute Details
#map(&blk) ⇒ Object
Returns the value of attribute map.
7 8 9 |
# File 'lib/pg-verify/model/variable_set.rb', line 7 def map @map end |
Instance Method Details
#+(varset) ⇒ Object
24 25 26 27 28 |
# File 'lib/pg-verify/model/variable_set.rb', line 24 def +(varset) varset = VariableSet.new(*varset) if varset.is_a?(Array) raise "Not a variable set '#{varset}'" unless varset.is_a?(VariableSet) return VariableSet.new(*(self.to_a() + varset.to_a())) end |
#<<(var) ⇒ Object
14 15 16 17 18 |
# File 'lib/pg-verify/model/variable_set.rb', line 14 def <<(var) return @map[var.name] = var if var.is_a?(Variable) return var.map { |v| self << v } if var.is_a?(Array) raise "Not a variable '#{var}'" end |
#[](name) ⇒ Object
38 39 40 41 42 |
# File 'lib/pg-verify/model/variable_set.rb', line 38 def [](name) name = name.to_sym raise "No such variable #{name}!" unless @map.key?(name) return @map[name] end |
#constname?(name) ⇒ Boolean
60 61 62 |
# File 'lib/pg-verify/model/variable_set.rb', line 60 def constname?(name) values().map(&:to_s).include?(name.to_s) end |
#empty? ⇒ Boolean
48 49 50 |
# File 'lib/pg-verify/model/variable_set.rb', line 48 def empty?() return @map.empty? end |
#get(*names) ⇒ Object
20 21 22 |
# File 'lib/pg-verify/model/variable_set.rb', line 20 def get(*names) return names.map { |n| self[n] } end |
#include?(name_or_var) ⇒ Boolean
44 45 46 |
# File 'lib/pg-verify/model/variable_set.rb', line 44 def include?(name_or_var) return varname?(name_or_var) || constname?(name_or_var) end |
#names ⇒ Object
34 35 36 |
# File 'lib/pg-verify/model/variable_set.rb', line 34 def names() return @map.keys() end |
#select_by_owner(owner) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/pg-verify/model/variable_set.rb', line 68 def select_by_owner(owner) owner = owner.name if owner.is_a?(Model::Component) owner = owner.to_sym if owner.is_a?(String) found = self.to_a().select { |var| var.owner_name == owner } return VariableSet.new(*found) end |
#to_a ⇒ Object
30 31 32 |
# File 'lib/pg-verify/model/variable_set.rb', line 30 def to_a() return @map.values() end |
#to_s ⇒ Object
64 65 66 |
# File 'lib/pg-verify/model/variable_set.rb', line 64 def to_s() return "{#{@map.map { |name, var| "#{name}:#{var.range}(#{var.owner_name})" }.join(", ")}}" end |
#values ⇒ Object
Returns all possible values of variables in this set as an array
76 77 78 |
# File 'lib/pg-verify/model/variable_set.rb', line 76 def values() return self.to_a().map(&:values).flatten end |
#varname?(name) ⇒ Boolean
56 57 58 |
# File 'lib/pg-verify/model/variable_set.rb', line 56 def varname?(name) return @map.key?(name.to_sym) end |