Class: Codinginfo::Cvar

Inherits:
Object show all
Defined in:
lib/codinginfo.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, package: nil, value: nil) ⇒ Cvar

Returns a new instance of Cvar.



13
14
15
16
17
# File 'lib/codinginfo.rb', line 13

def initialize(name:, package: nil, value: nil)
  @name = name
  @package = package
  @value = value
end

Instance Attribute Details

#nameObject (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

#packageObject (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

#valueObject (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



26
# File 'lib/codinginfo.rb', line 26

def ==(other) = name == other.name

#combine(other) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/codinginfo.rb', line 28

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_prefixObject



19
20
21
22
23
# File 'lib/codinginfo.rb', line 19

def label_prefix
  return /^#{name}_(\w+_)?#{value}\./ if package.nil?

  [name, package, value].join("_") + "."
end

#to_sObject



25
# File 'lib/codinginfo.rb', line 25

def to_s = "#{name}=#{value}"