Class: FormatParser::FDXParser

Inherits:
Object
  • Object
show all
Includes:
IOUtils
Defined in:
lib/parsers/fdx_parser.rb

Instance Method Summary collapse

Methods included from IOUtils

#safe_read, #safe_skip

Instance Method Details

#call(io) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/parsers/fdx_parser.rb', line 4

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



20
21
22
23
24
25
26
27
# File 'lib/parsers/fdx_parser.rb', line 20

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

#xml_check(io) ⇒ Object



15
16
17
18
# File 'lib/parsers/fdx_parser.rb', line 15

def xml_check(io)
  xml_check = safe_read(io, 5)
  xml_check == '<?xml'
end