Class: I18nExtract::Extractor
- Inherits:
-
Object
- Object
- I18nExtract::Extractor
- Defined in:
- lib/i18n_extract/extractor.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #extract ⇒ Object
-
#initialize(path) ⇒ Extractor
constructor
A new instance of Extractor.
- #validate! ⇒ Object
Constructor Details
#initialize(path) ⇒ Extractor
Returns a new instance of Extractor.
24 25 26 27 28 29 |
# File 'lib/i18n_extract/extractor.rb', line 24 def initialize path @path = path @buffer = Parser::Source::Buffer.new(@path) @buffer.source = File.read(@path) @parser = BetterHtml::Parser.new(@buffer) end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
22 23 24 |
# File 'lib/i18n_extract/extractor.rb', line 22 def path @path end |
Instance Method Details
#extract ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/i18n_extract/extractor.rb', line 31 def extract children = @parser.ast HTMLIterator.descendants(children).reject { |node| node.children.reject{|child| !child.is_a?(String) }.map(&:strip).join('').empty? }.to_a end |
#validate! ⇒ Object
39 40 41 42 43 44 |
# File 'lib/i18n_extract/extractor.rb', line 39 def validate! res = extract res.each do |node| raise ExtractError.new(node, "Found hard coded string") unless node.children.join('').blank? end end |