kputnam/stupidedi

View on GitHub
bin/edi-ed

Summary

Maintainability
Test Coverage
#!/usr/bin/env ruby
require "pathname"
$:.unshift(File.expand_path("../../lib", Pathname.new(__FILE__).realpath))

require "stupidedi"
require "pp"

# This will be auto-enabled when $stdout.tty?, but -C forces color output
require "term/ansicolor" if ARGV.delete("-C")

config = Stupidedi::Config.hipaa
config.editor.tap do |c|
  c.register(Stupidedi::Interchanges::FourOhOne::InterchangeDef) { Stupidedi::Editor::FiveOhOneEd }
  c.register(Stupidedi::Interchanges::FiveOhOne::InterchangeDef) { Stupidedi::Editor::FiveOhOneEd }

  c.register(Stupidedi::Versions::FortyTen::FunctionalGroupDef) { Stupidedi::Editor::FiftyTenEd }
  c.register(Stupidedi::Versions::FiftyTen::FunctionalGroupDef) { Stupidedi::Editor::FiftyTenEd }

  c.register(Stupidedi::TransactionSets::FiftyTen::Implementations::X222A1::HC837) { Stupidedi::Editor::X222 }
end

parser = Stupidedi::Parser.build(config)
start  = Time.now

ARGV.each do |path|
  File.open(path) do |io|
    parser, = parser.read(Stupidedi::Reader.build(io))
  end
end

envelope_ed = Stupidedi::Editor::TransmissionEd.new(config, Time.now)
pp envelope_ed.critique(parser).results

stop = Time.now

begin
  a = parser.first
  b = parser.last

  a.flatmap{|_a| b.flatmap{|_b| _a.distance(_b) }}.
    tap{|d| puts "#{d + 1} segments" }
end

puts "%0.3f seconds" % (stop - start)