Class: Y2Network::UdevRulePart

Inherits:
Object
  • Object
show all
Includes:
Yast2::Equatable, Yast::Logger
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



77
78
79
80
81
# File 'src/lib/y2network/udev_rule_part.rb', line 77

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

Instance Attribute Details

#keyString

Returns Key name.

Returns:

  • (String)

    Key name



63
64
65
# File 'src/lib/y2network/udev_rule_part.rb', line 63

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.



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

def operator
  @operator
end

#valueString

Returns Value to match or assign.

Returns:

  • (String)

    Value to match or assign



68
69
70
# File 'src/lib/y2network/udev_rule_part.rb', line 68

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:



51
52
53
54
55
56
57
58
59
60
# File 'src/lib/y2network/udev_rule_part.rb', line 51

def from_string(str)
  match = PART_REGEXP.match(str)

  if match.nil?
    log.info("Not matching udev rule: #{str}")
    return
  end

  new(match[:key], match[:operator], match[:value])
end

Instance Method Details

#bus_id?Boolean

Return whether the udev rule part is the interface bus_id or not

Returns:

  • (Boolean)


92
93
94
# File 'src/lib/y2network/udev_rule_part.rb', line 92

def bus_id?
  (key == "KERNELS") && (operator == "==")
end

#dev_port?Boolean

Return whether the udev rule part is the interface dev_port or not

Returns:

  • (Boolean)


99
100
101
# File 'src/lib/y2network/udev_rule_part.rb', line 99

def dev_port?
  (key == "ATTR{dev_port}") && (operator == "==")
end

#mac?Boolean

Return whether the udev rule part is the interface MAC address or not

Returns:

  • (Boolean)


106
107
108
# File 'src/lib/y2network/udev_rule_part.rb', line 106

def mac?
  (key == "ATTR{address}") && (operator == "==")
end

#name?Boolean

Return whether the udev rule part is the interface name or not

Returns:

  • (Boolean)


113
114
115
# File 'src/lib/y2network/udev_rule_part.rb', line 113

def name?
  (key == "NAME") && (operator == "=")
end

#to_sString

Returns an string representation of the udev rule part

Returns:

  • (String)


86
87
88
# File 'src/lib/y2network/udev_rule_part.rb', line 86

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