Class: I18nliner::Extractors::RubyExtractor

Inherits:
SexpProcessor
  • Object
show all
Includes:
SexpHelper
Defined in:
lib/i18nliner/extractors/ruby_extractor.rb

Constant Summary collapse

TRANSLATE_CALLS =
i[t translate].freeze

Constants included from SexpHelper

SexpHelper::UnsupportedExpression

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SexpHelper

#raw, #string_concatenation?, #string_from, #stringish?

Constructor Details

#initialize(sexps, scope) ⇒ RubyExtractor



20
21
22
23
24
# File 'lib/i18nliner/extractors/ruby_extractor.rb', line 20

def initialize(sexps, scope)
  @sexps = sexps
  @scope = scope
  super()
end

Instance Attribute Details

#current_defnObject (readonly)

Returns the value of attribute current_defn.



14
15
16
# File 'lib/i18nliner/extractors/ruby_extractor.rb', line 14

def current_defn
  @current_defn
end

#current_lineObject (readonly)

Returns the value of attribute current_line.



14
15
16
# File 'lib/i18nliner/extractors/ruby_extractor.rb', line 14

def current_line
  @current_line
end

Class Method Details

.patternObject



16
17
18
# File 'lib/i18nliner/extractors/ruby_extractor.rb', line 16

def self.pattern
  /(^|\W)(t|translate)(\W|$)/
end

Instance Method Details

#each_translation(&block) ⇒ Object



26
27
28
29
# File 'lib/i18nliner/extractors/ruby_extractor.rb', line 26

def each_translation(&block)
  @block = block
  process(@sexps)
end

#process_call(exp) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/i18nliner/extractors/ruby_extractor.rb', line 39

def process_call(exp)
  exp.shift
  receiver_exp = exp.shift
  receiver = nil
  if receiver_exp
    receiver = (receiver_exp[0] == :const) ? receiver_exp.last : UnsupportedExpression
    process(receiver_exp)
  end
  method = exp.shift

  if extractable_call?(receiver, method)
    @current_line = exp.line

    # convert s-exps into literals where possible
    args = process_arguments(exp)

    process_translate_call(receiver, method, args)
  else
    # even if this isn't a translate call, its arguments might contain
    # one
    process exp.shift until exp.empty?
  end

  s
end

#process_defn(exp) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/i18nliner/extractors/ruby_extractor.rb', line 31

def process_defn(exp)
  exp.shift
  @current_defn = exp.shift
  process exp.shift until exp.empty?
  @current_defn = nil
  s
end