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.



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

#assignmentsObject

Returns the value of attribute assignments.



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

def assignments
  @assignments
end

#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



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_prefixObject



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

Returns:

  • (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_sObject



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

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