Class: ExtractI18n::HTMLExtractor::Match::AttributeMatch

Inherits:
BaseMatch show all
Defined in:
lib/extract_i18n/html_extractor/match/attribute_match.rb

Instance Attribute Summary

Attributes inherited from BaseMatch

#node

Attributes inherited from NodeMatch

#document, #key, #text

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from NodeMatch

#translation_key_object

Constructor Details

#initialize(document, node, text, attribute) ⇒ AttributeMatch

Returns a new instance of AttributeMatch.



5
6
7
8
# File 'lib/extract_i18n/html_extractor/match/attribute_match.rb', line 5

def initialize(document, node, text, attribute)
  super(document, node, text)
  @attribute = attribute
end

Class Method Details

.create(document, node, attribute) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/extract_i18n/html_extractor/match/attribute_match.rb', line 10

def self.create(document, node, attribute)
  if node[attribute] && !node[attribute].empty?
    [new(document, node, node[attribute], attribute)]
  else
    []
  end
end

Instance Method Details

#replace_text!(key, i18n_t) ⇒ Object



18
19
20
21
# File 'lib/extract_i18n/html_extractor/match/attribute_match.rb', line 18

def replace_text!(key, i18n_t)
  document.erb_directives[key] = i18n_t
  node[@attribute] = "@@=#{key}@@"
end