Class: YAMLRewriter::Rule
- Inherits:
-
Object
- Object
- YAMLRewriter::Rule
- Defined in:
- lib/yaml_rewriter/rule.rb
Instance Method Summary collapse
-
#initialize(rule) ⇒ Rule
constructor
A new instance of Rule.
- #match?(path, reverse:) ⇒ Boolean
- #replacement(key, reverse:) ⇒ Object
Constructor Details
#initialize(rule) ⇒ Rule
Returns a new instance of Rule.
3 4 5 |
# File 'lib/yaml_rewriter/rule.rb', line 3 def initialize(rule) @rule = rule end |
Instance Method Details
#match?(path, reverse:) ⇒ Boolean
7 8 9 10 11 |
# File 'lib/yaml_rewriter/rule.rb', line 7 def match?(path, reverse:) rule_path = @rule[0..-2] + (reverse ? [@rule.last.values.first] : [@rule.last.keys.first]) rule_path == (path[(path.size-@rule.size)..-1]) end |
#replacement(key, reverse:) ⇒ Object
13 14 15 16 17 |
# File 'lib/yaml_rewriter/rule.rb', line 13 def replacement(key, reverse:) reverse ? @rule.last.invert[key] : @rule.last[key] end |