class ExtractI18n::HTMLExtractor::Match::Finder
Attributes
document[R]
Public Class Methods
new(document)
click to toggle source
# File lib/extract_i18n/html_extractor/match.rb, line 7 def initialize(document) @document = document end
Public Instance Methods
matches()
click to toggle source
# File lib/extract_i18n/html_extractor/match.rb, line 11 def matches erb_nodes(document) + plain_text_nodes(document) + form_fields(document) end
Private Instance Methods
erb_nodes(document)
click to toggle source
# File lib/extract_i18n/html_extractor/match.rb, line 17 def erb_nodes(document) document.erb_directives.map do |fragment_id, _| ErbDirectiveMatch.create(document, fragment_id) end.flatten.compact end
form_fields(document)
click to toggle source
# File lib/extract_i18n/html_extractor/match.rb, line 27 def form_fields(document) ExtractI18n.html_fields_with_plaintext.flat_map do |field| document. css("[#{field}]"). select { |input| input[field] && !input[field].empty? }. reject { |n| n[field] =~ /\@\@(=?)[a-z0-9\-]+\@\@/ }. flat_map { |node| AttributeMatch.create(document, node, field) } end.compact end
leaf_nodes()
click to toggle source
# File lib/extract_i18n/html_extractor/match.rb, line 37 def leaf_nodes @leaf_nodes ||= document.css('*:not(:has(*))').select { |n| n.text && !n.text.empty? } end
plain_text_nodes(document)
click to toggle source
# File lib/extract_i18n/html_extractor/match.rb, line 23 def plain_text_nodes(document) leaf_nodes.map! { |node| PlainTextMatch.create(document, node) }.flatten.compact end