Class: I18nChecker::Locale::TextProcessor

Inherits:
Parser::AST::Processor
  • Object
show all
Defined in:
lib/i18n_checker/locale/text_processor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file:, locale_texts: []) ⇒ TextProcessor

Returns a new instance of TextProcessor.



9
10
11
12
# File 'lib/i18n_checker/locale/text_processor.rb', line 9

def initialize(file:, locale_texts: [])
  @file = file
  @locale_texts = locale_texts
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



7
8
9
# File 'lib/i18n_checker/locale/text_processor.rb', line 7

def file
  @file
end

#locale_textsObject (readonly)

Returns the value of attribute locale_texts.



7
8
9
# File 'lib/i18n_checker/locale/text_processor.rb', line 7

def locale_texts
  @locale_texts
end

Instance Method Details

#on_send(node) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/i18n_checker/locale/text_processor.rb', line 14

def on_send(node)
  _, method_name, *arg_nodes = *node
  return super(node) unless method_name == :t
  arg_node = arg_nodes.first
  locale_texts << I18nChecker::Locale::Text.new(
    file: file,
    line: arg_node.loc.line,
    column: arg_node.loc.column + 1,
    text: arg_node.children.first,
  )
  super(node)
end