Class: Y2Network::UdevRulePart
- Inherits:
-
Object
- Object
- Y2Network::UdevRulePart
- 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
-
#==(other) ⇒ Boolean
(also: #eql?)
Determines whether two udev rule parts are equivalent.
-
#initialize(key, operator, value) ⇒ UdevRulePart
constructor
Constructor.
-
#to_s ⇒ String
Returns an string representation of the udev rule part.
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
#key ⇒ String
Returns Key name.
53 54 55 |
# File 'src/lib/y2network/udev_rule_part.rb', line 53 def key @key end |
#operator ⇒ String
Returns 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 |
#value ⇒ String
Returns 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.
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_s ⇒ String
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 |