Class: I18nliner::Extractors::RubyExtractor

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

Constant Summary collapse

TRANSLATE_CALLS =
[:t, :translate]

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

Returns a new instance of RubyExtractor.



18
19
20
21
22
# File 'lib/i18nliner/extractors/ruby_extractor.rb', line 18

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

Instance Attribute Details

#current_defnObject (readonly)

Returns the value of attribute current_defn.



29
30
31
# File 'lib/i18nliner/extractors/ruby_extractor.rb', line 29

def current_defn
  @current_defn
end

#current_lineObject (readonly)

Returns the value of attribute current_line.



12
13
14
# File 'lib/i18nliner/extractors/ruby_extractor.rb', line 12

def current_line
  @current_line
end

Class Method Details

.patternObject



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

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

Instance Method Details

#each_translation(&block) ⇒ Object



24
25
26
27
# File 'lib/i18nliner/extractors/ruby_extractor.rb', line 24

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

#process_call(exp) ⇒ Object



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

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



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

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