Module: ReadyForI18N::ExtractorBase

Included in:
ErbHelperExtractor, HtmlTextExtractor
Defined in:
lib/extractor_base.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.key_mapperObject



15
16
17
# File 'lib/extractor_base.rb', line 15

def self.key_mapper
  @key_mapper
end

.key_mapper=(mapper) ⇒ Object



12
13
14
# File 'lib/extractor_base.rb', line 12

def self.key_mapper=(mapper)
  @key_mapper = mapper
end

.use_dot(on_off) ⇒ Object



6
7
8
# File 'lib/extractor_base.rb', line 6

def self.use_dot(on_off)
  @use_dot = on_off
end

.use_dot?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/extractor_base.rb', line 9

def self.use_dot?
  @use_dot
end

Instance Method Details

#can_replace?(e) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/extractor_base.rb', line 39

def can_replace?(e)
  e.strip.size > 1
end

#extract(input) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/extractor_base.rb', line 19

def extract(input)
  buffer = StringIO.new
  input.each do |line|
    unless skip_line?(line)
      values_in_line(line).each do |e|
        if can_replace?(e)
          yield(to_key(e),to_value(e)) if block_given?
          replace_line(line,e)
        end
      end
    end
    buffer << line
  end
  buffer.string
end

#t_method(val, wrap = false) ⇒ Object



42
43
44
45
# File 'lib/extractor_base.rb', line 42

def t_method(val,wrap=false)
  m = ExtractorBase.use_dot? ? "t('.#{to_key(val)}')" : "t(:#{to_key(val)})"
  wrap ? "<%=#{m}%>" : m
end

#to_key(s) ⇒ Object



34
35
36
37
38
# File 'lib/extractor_base.rb', line 34

def to_key(s)
  val = to_value(s)
  result = (ExtractorBase.key_mapper) ? ExtractorBase.key_mapper.key_for(val) : val.scan(/\w+/).join('_').downcase
  key_prefix ? "#{key_prefix}_#{result}" : result
end