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

Parameters:

  • key (String)

    Key name

  • operator (String)

    Operator ("==", "!=", "=", "+=", "-=", ":=")

  • value (String)

    Value to match or assign


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

Returns Key name.

Returns:

  • (String)

    Key name


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

def key
  @key
end

#operatorString

Returns Operator. There are two comparison operators ("==", "!=") and four assignment operators ("=", "+=", "-=", ":="). See udev(7) for further information.

Returns:

  • (String)

    Operator. There are two comparison operators ("==", "!=") and four assignment operators ("=", "+=", "-=", ":="). See udev(7) for further information.


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

def operator
  @operator
end

#valueString

Returns Value to match or assign.

Returns:

  • (String)

    Value to match or assign


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

def value
  @value
end

Class Method Details

.from_string(str) ⇒ UdevRulePart

Returns udev rule object.

Parameters:

  • str (String)

    string form of an udev rule

Returns:


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

Parameters:

Returns:

  • (Boolean)

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

Returns:

  • (String)

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

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