Class: Y2Network::UdevRulePart
- Inherits:
-
Object
- Object
- Y2Network::UdevRulePart
- 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
-
#key ⇒ String
Key name.
-
#operator ⇒ String
Operator.
-
#value ⇒ String
Value to match or assign.
Class Method Summary collapse
-
.from_string(str) ⇒ UdevRulePart
Udev rule object.
Instance Method Summary collapse
-
#bus_id? ⇒ Boolean
Return whether the udev rule part is the interface bus_id or not.
-
#dev_port? ⇒ Boolean
Return whether the udev rule part is the interface dev_port or not.
-
#initialize(key, operator, value) ⇒ UdevRulePart
constructor
Constructor.
-
#mac? ⇒ Boolean
Return whether the udev rule part is the interface MAC address or not.
-
#name? ⇒ Boolean
Return whether the udev rule part is the interface name or not.
-
#to_s ⇒ String
Returns an string representation of the udev rule part.
Constructor Details
#initialize(key, operator, value) ⇒ UdevRulePart
Constructor
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
#key ⇒ String
Returns Key name.
63 64 65 |
# File 'src/lib/y2network/udev_rule_part.rb', line 63 def key @key end |
#operator ⇒ String
Returns 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 |
#value ⇒ String
Returns 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.
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
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
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
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
113 114 115 |
# File 'src/lib/y2network/udev_rule_part.rb', line 113 def name? (key == "NAME") && (operator == "=") end |
#to_s ⇒ String
Returns an string representation of the udev rule part
86 87 88 |
# File 'src/lib/y2network/udev_rule_part.rb', line 86 def to_s "#{key}#{operator}\"#{value}\"" end |