Class: PutText::Extractor
- Inherits:
-
Object
- Object
- PutText::Extractor
- Defined in:
- lib/puttext/extractor.rb
Defined Under Namespace
Classes: NoSuchFileError, UnsupportedFileError
Constant Summary collapse
- EXTENSIONS =
{ '.rb' => 'Ruby', '.slim' => 'Slim' }.freeze
Class Method Summary collapse
-
.file_supported?(path) ⇒ Boolean
Check if a file is supported by the parser, based on its extension.
-
.parser_class_by_name(name) ⇒ Class
Return the class of a parser by its name.
Instance Method Summary collapse
-
#extract(path) ⇒ POFile
Extract strings from files in the given path.
-
#extract_from_file(path) ⇒ Array<POEntry>
Parse gettext strings from a file in the path.
Class Method Details
.file_supported?(path) ⇒ Boolean
Check if a file is supported by the parser, based on its extension.
30 31 32 33 34 35 36 37 38 |
# File 'lib/puttext/extractor.rb', line 30 def self.file_supported?(path) EXTENSIONS.each do |ext, parser_name| next unless path.end_with?(ext) next unless parser_class_by_name(parser_name) return true end false end |
Instance Method Details
#extract(path) ⇒ POFile
Extract strings from files in the given path.
45 46 47 48 49 50 |
# File 'lib/puttext/extractor.rb', line 45 def extract(path) files = files_in_path(path) supported_files = filter_files(files) parse_files(supported_files) end |
#extract_from_file(path) ⇒ Array<POEntry>
Parse gettext strings from a file in the path.
56 57 58 |
# File 'lib/puttext/extractor.rb', line 56 def extract_from_file(path) parser_by_path(path).strings_from_file(path) end |