Class: YAMLRewriter::Rule

Inherits:
Object
  • Object
show all
Defined in:
lib/yaml_rewriter/rule.rb

Instance Method Summary collapse

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

Returns:

  • (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