Class: FormatParser::FDXParser

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

Constant Summary

Constants included from IOUtils

IOUtils::INTEGER_DIRECTIVES

Instance Method Summary collapse

Methods included from IOUtils

#read_bytes, #read_fixed_point, #read_int, #safe_read, #safe_skip, #skip_bytes

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')
    [:fdx, :script]
  else
    nil
  end
end

#likely_match?(filename) ⇒ Boolean

Returns:

  • (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