Sha256: 795e0e5a69bb8385bfedc98cfd02f1adc9ffe49e7a1557803a8a0ecf6fc50a9a

Contents?: true

Size: 841 Bytes

Versions: 20

Compression:

Stored size: 841 Bytes

Contents

class FormatParser::FDXParser
  include FormatParser::IOUtils

  def likely_match?(filename)
    filename =~ /\.fdx$/i
  end

  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

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

  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

  FormatParser.register_parser new, natures: :document, formats: :fdx
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
format_parser-2.10.0 lib/parsers/fdx_parser.rb
format_parser-2.9.0 lib/parsers/fdx_parser.rb
format_parser-2.8.0 lib/parsers/fdx_parser.rb
format_parser-2.7.2 lib/parsers/fdx_parser.rb
format_parser-2.7.1 lib/parsers/fdx_parser.rb
format_parser-2.7.0 lib/parsers/fdx_parser.rb
format_parser-2.6.0 lib/parsers/fdx_parser.rb
format_parser-2.5.0 lib/parsers/fdx_parser.rb
format_parser-2.4.5 lib/parsers/fdx_parser.rb
format_parser-2.4.4 lib/parsers/fdx_parser.rb
format_parser-2.4.3 lib/parsers/fdx_parser.rb
format_parser-2.3.0 lib/parsers/fdx_parser.rb
format_parser-2.2.1 lib/parsers/fdx_parser.rb
format_parser-2.2.0 lib/parsers/fdx_parser.rb
format_parser-2.1.0 lib/parsers/fdx_parser.rb
format_parser-2.0.0 lib/parsers/fdx_parser.rb
format_parser-2.0.0.pre.4 lib/parsers/fdx_parser.rb
format_parser-2.0.0.pre.3 lib/parsers/fdx_parser.rb
format_parser-2.0.0.pre.2 lib/parsers/fdx_parser.rb
format_parser-2.0.0.pre lib/parsers/fdx_parser.rb