Sha256: c3d54a7d52ba310db0db36423e22db1f414b06b8d9109831ddafd6273212ee55

Contents?: true

Size: 1.39 KB

Versions: 1

Compression:

Stored size: 1.39 KB

Contents

module AAMVA
  class Encoder
    attr_reader :standard, :data

    def initialize(standard:, data:)
      @standard = standard
      @data = data
    end

    def string
      "#{header}#{subfile_designators}#{subfiles}"
    end

    def pdf417
      @pdf417 ||= begin
        require "pdf417"

        PDF417.new(string)
      end
    end

    def png
      @png ||= pdf417.to_chunky_png
    end

    private

    def header
      @header ||= begin
        [
          standard.spec.fetch("compliance_indicator"),
          standard.spec.fetch("data_element_separator"),
          standard.spec.fetch("record_separator"),
          standard.spec.fetch("segment_terminator"),
          standard.spec.fetch("file_type"),
          data.header.issuer_identification_number,
          standard.spec.fetch("aamva_version_number"),
          data.header.jurisdiction_version_number,
          data.header.number_of_entries
        ].join("")

      end
    end

    def subfile_designators
      @subfile_designators ||= data.subfile_designators.map do |designator|
        "#{designator.type}#{designator.offset}#{designator.length}"
      end.join("")
    end

    def subfiles
      @subfiles ||= Calculator.subfiles(
        subfiles: data.subfiles,
        data_element_separator: standard.spec.fetch("data_element_separator"),
        segment_terminator: standard.spec.fetch("segment_terminator")
      )
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
aamva-0.2.0 lib/aamva/encoder.rb