Class: I18n::Tasks::Scanners::AstMatchers::MessageReceiversMatcher

Inherits:
BaseMatcher
  • Object
show all
Defined in:
lib/i18n/tasks/scanners/ast_matchers/message_receivers_matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(scanner:, receivers:, message:) ⇒ MessageReceiversMatcher

Returns a new instance of MessageReceiversMatcher.



8
9
10
11
12
# File 'lib/i18n/tasks/scanners/ast_matchers/message_receivers_matcher.rb', line 8

def initialize(scanner:, receivers:, message:)
  super(scanner: scanner)
  @receivers = Array(receivers)
  @message = message
end

Instance Method Details

#convert_to_key_occurrences(send_node, method_name, location: send_node.loc) ⇒ nil, [key, Occurrence]

Returns full absolute key name and the occurrence.

Parameters:

  • send_node (Parser::AST::Node)
  • method_name (Symbol, nil)
  • location (Parser::Source::Map) (defaults to: send_node.loc)

Returns:

  • (nil, [key, Occurrence])

    full absolute key name and the occurrence.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/i18n/tasks/scanners/ast_matchers/message_receivers_matcher.rb', line 18

def convert_to_key_occurrences(send_node, method_name, location: send_node.loc)
  return unless node_match?(send_node)

  receiver = send_node.children[0]
  first_arg_node = send_node.children[2]
  second_arg_node = send_node.children[3]

  key = extract_string(first_arg_node)
  return if key.nil?

  key, default_arg = process_options(node: second_arg_node, key: key)

  return if key.nil?

  [
    full_key(receiver: receiver, key: key, location: location, calling_method: method_name),
    I18n::Tasks::Scanners::Results::Occurrence.from_range(
      raw_key: key,
      range: location.expression,
      default_arg: default_arg
    )
  ]
end