#!/usr/bin/env ruby require "flex_station_data/services/load_plates" require "flex_station_data/presenters/plates_csv" module FlexStationData class SampleDataApp include Concerns::Service OPTION_RE = /\A--(\w+(?:-\w+)*)(?:=(.*))?\z/.freeze attr_reader :args, :options def initialize(*args) @options, @args = args.partition { |arg| arg =~ OPTION_RE } @options.map! do |option| option.scan(OPTION_RE).first end end def threshold name, value = options.reverse.detect { |name, value| name == "threshold" } return nil if name.blank? Float(value) end def files @files ||= args.map { |arg| Pathname(arg) } end def plates @plates ||= files.map do |file| [ file, LoadPlates.call(file) ] end end def csv plates.flat_map do |file, file_plates| Presenters::PlatesCsv.present(file, file_plates, threshold: threshold) end end def call CSV do |out| csv.each do |row| out << row end end end end end FlexStationData::SampleDataApp.call(*ARGV)