Class: FormatParser::FDXParser
- Inherits:
-
Object
- Object
- FormatParser::FDXParser
- Includes:
- IOUtils
- Defined in:
- lib/parsers/fdx_parser.rb
Instance Method Summary collapse
- #call(io) ⇒ Object
- #check_for_document_type(file_and_document_type) ⇒ Object
- #likely_match?(filename) ⇒ Boolean
- #xml_check(io) ⇒ Object
Methods included from IOUtils
Instance Method Details
#call(io) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/parsers/fdx_parser.rb', line 8 def call(io) return unless xml_check(io) file_and_document_type = safe_read(io, 100) file_type, document_type = check_for_document_type(file_and_document_type) return if file_type != :fdx FormatParser::Document.new( format: file_type, document_type: document_type ) end |
#check_for_document_type(file_and_document_type) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/parsers/fdx_parser.rb', line 24 def check_for_document_type(file_and_document_type) sanitized_data = file_and_document_type.downcase if sanitized_data.include?('finaldraft') && sanitized_data.include?('script') return :fdx, :script else return end end |
#likely_match?(filename) ⇒ Boolean
4 5 6 |
# File 'lib/parsers/fdx_parser.rb', line 4 def likely_match?(filename) filename =~ /\.fdx$/i end |
#xml_check(io) ⇒ Object
19 20 21 22 |
# File 'lib/parsers/fdx_parser.rb', line 19 def xml_check(io) xml_check = safe_read(io, 5) xml_check == '<?xml' end |