Class: Y2Network::UdevRulePart

Inherits:
Object
  • Object
show all
Defined in:
src/lib/y2network/udev_rule_part.rb

Overview

Simple class to represent a key-value pair in a UdevRule.

This class does not check whether operators or keys/values are valid or not. We can implement that logic later if required.

Constant Summary collapse

PART_REGEXP =

Regular expression to match a udev rule part

Regexp.new("\\A(?<key>[A-Za-z\{\}]+)(?<operator>[^\"]+)\"(?<value>.+)\"\\Z")

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, operator, value) ⇒ UdevRulePart

Constructor


65
66
67
68
69
# File 'src/lib/y2network/udev_rule_part.rb', line 65

def initialize(key, operator, value)
  @key = key
  @operator = operator
  @value = value
end

Instance Attribute Details

#keyString


53
54
55
# File 'src/lib/y2network/udev_rule_part.rb', line 53

def key
  @key
end

#operatorString


56
57
58
# File 'src/lib/y2network/udev_rule_part.rb', line 56

def operator
  @operator
end

#valueString


58
59
60
# File 'src/lib/y2network/udev_rule_part.rb', line 58

def value
  @value
end

Class Method Details

.from_string(str) ⇒ UdevRulePart


46
47
48
49
50
# File 'src/lib/y2network/udev_rule_part.rb', line 46

def from_string(str)
  match = PART_REGEXP.match(str)
  return if match.nil?
  new(match[:key], match[:operator], match[:value])
end

Instance Method Details

#==(other) ⇒ Boolean Also known as: eql?

Determines whether two udev rule parts are equivalent


75
76
77
# File 'src/lib/y2network/udev_rule_part.rb', line 75

def ==(other)
  key == other.key && operator == other.operator && value == other.value
end

#to_sString

Returns an string representation of the udev rule part


84
85
86
# File 'src/lib/y2network/udev_rule_part.rb', line 84

def to_s
  "#{key}#{operator}\"#{value}\""
end