Class: Codinginfo::Cvar
Instance Attribute Summary collapse
-
#assignments ⇒ Object
Returns the value of attribute assignments.
-
#name ⇒ Object
readonly
The CVAR must have a name and may have a package and value the package and value can be merged.
-
#package ⇒ Object
readonly
The CVAR must have a name and may have a package and value the package and value can be merged.
-
#value ⇒ Object
readonly
The CVAR must have a name and may have a package and value the package and value can be merged.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #combine(other) ⇒ Object
-
#initialize(name:, package: nil, value: nil) ⇒ Cvar
constructor
A new instance of Cvar.
- #label_prefix ⇒ Object
- #match?(label) ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(name:, package: nil, value: nil) ⇒ Cvar
Returns a new instance of Cvar.
14 15 16 17 18 19 |
# File 'lib/codinginfo.rb', line 14 def initialize(name:, package: nil, value: nil) @name = name @package = package @value = value @assignments = [] end |
Instance Attribute Details
#assignments ⇒ Object
Returns the value of attribute assignments.
13 14 15 |
# File 'lib/codinginfo.rb', line 13 def assignments @assignments end |
#name ⇒ Object (readonly)
The CVAR must have a name and may have a package and value the package and value can be merged
12 13 14 |
# File 'lib/codinginfo.rb', line 12 def name @name end |
#package ⇒ Object (readonly)
The CVAR must have a name and may have a package and value the package and value can be merged
12 13 14 |
# File 'lib/codinginfo.rb', line 12 def package @package end |
#value ⇒ Object (readonly)
The CVAR must have a name and may have a package and value the package and value can be merged
12 13 14 |
# File 'lib/codinginfo.rb', line 12 def value @value end |
Instance Method Details
#==(other) ⇒ Object
39 |
# File 'lib/codinginfo.rb', line 39 def ==(other) = name == other.name |
#combine(other) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/codinginfo.rb', line 41 def combine(other) fail "Cannot combine #{name} with #{other.name}" unless self == other self.class.new \ name: name, package: package || other.package, value: value || other.value end |
#label_prefix ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/codinginfo.rb', line 30 def label_prefix if package [name, package, value].join("_") + "." else /^#{name}_([A-Za-z0-9]+_)?#{value}\./ end end |
#match?(label) ⇒ Boolean
21 22 23 24 25 26 27 28 |
# File 'lib/codinginfo.rb', line 21 def match?(label) # assignments # .values # .select { _1.name == name } # .map { combine(_1) } # .any? { label.name.match?(_1.label_prefix) } label.name.match?(label_prefix) end |
#to_s ⇒ Object
38 |
# File 'lib/codinginfo.rb', line 38 def to_s = "#{name}=#{value}" |