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.
-
#package ⇒ Object
readonly
The CVAR must have a name and may have a package and value.
-
#value ⇒ Object
readonly
The CVAR must have a name and may have a package and value.
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.
15 16 17 18 19 20 |
# File 'lib/codinginfo.rb', line 15 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.
14 15 16 |
# File 'lib/codinginfo.rb', line 14 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
13 14 15 |
# File 'lib/codinginfo.rb', line 13 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
13 14 15 |
# File 'lib/codinginfo.rb', line 13 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
13 14 15 |
# File 'lib/codinginfo.rb', line 13 def value @value end |
Instance Method Details
#==(other) ⇒ Object
40 |
# File 'lib/codinginfo.rb', line 40 def ==(other) = name == other.name |
#combine(other) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/codinginfo.rb', line 42 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
31 32 33 34 35 36 37 |
# File 'lib/codinginfo.rb', line 31 def label_prefix @label_prefix ||= if package [name, package, value].join("_") + "." else /^#{name}_([A-Za-z0-9]+_)?#{value}\./ end end |
#match?(label) ⇒ Boolean
22 23 24 25 26 27 28 29 |
# File 'lib/codinginfo.rb', line 22 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
39 |
# File 'lib/codinginfo.rb', line 39 def to_s = "#{name}=#{value}" |