class PotaCsvToAdif::LogFile

Attributes

file_path[R]

Public Class Methods

new(file_path) click to toggle source
# File lib/ruby-pota-csv-to-adif.rb, line 25
def initialize(file_path)
  @file_path = file_path
end

Public Instance Methods

convert() click to toggle source
# File lib/ruby-pota-csv-to-adif.rb, line 29
def convert
  file = File.open(file_path)
  csv = CSV.new(file, headers: true)
  adif_file = File.new("#{file_path[0...file_path.rindex('.')]}.adi", 'w')

  adif_file.puts header

  csv.each do |row|
    adif_file.puts "#{field('CALL', row)}#{field('QSO_DATE', row)}#{field('TIME_ON', row)}#{field('BAND', row)}#{field('MODE', row)}#{field('OPERATOR', row)}<MY_SIG:4>POTA #{field('MY_SIG_INFO', row)}#{field('SIG_INFO', row)}#{field('STATION_CALLSIGN', row)}<EOR>"
  end
end

Private Instance Methods

field(name, row) click to toggle source
# File lib/ruby-pota-csv-to-adif.rb, line 59
def field(name, row)
  value = row[name]&.strip
  return if value.nil?
  "<#{name.upcase}:#{value.size}>#{value} "
end
header() click to toggle source
# File lib/ruby-pota-csv-to-adif.rb, line 45
    def header
      <<-ADIF_HEAD
ADIF Export from ruby-pota-csv-to-adif v[0.1]
https://github.com/ecopony/ruby-pota-csv-to-adif
Copyright (C) 2021 Edward Copony
File generated on #{Time.now.getutc.strftime('%d %b, %Y at %I:%M')}
<ADIF_VER:5>3.1.0
<PROGRAMID:21>ruby-pota-csv-to-adif
<PROGRAMVERSION:3>0.1
<EOH>

      ADIF_HEAD
    end