Ham::Convert::FrequencyList - Convert Frequency List files between formats
version v0.0.1
use Ham::Convert::FrequencyList;
Provides converters between different formats of frequency lists commonly used to program frequencies into amateur radio equipment. Different radios use different software to program them, sometimes just by preference. Trading frequency lists can be difficult due to these incompatibilities in the formats and the inability for one piece of software to read files another. This code aims to make it easier to convert from one format to another to ease that pain.
my $converter = Ham::Convert::FrequencyList->new(
...,
);
my @list = @{ Ham::Convert::FreqencyList->new->read($file) };
Reads an arrayref of frequencies from a valid argument to
Text::CSV/in.
The frequencies returned are a list of hashrefs or undef,
the hashrefs are keyed off the "internal_header" name.
Ham::Convert::FreqencyList->new->write( $file, \@list );
Writes an arrayref of frequency definitions to the specified $file.
Returns a list of the header names for the columns in the current format.
These methods are used by subclasses to set up conversions.
Returns a list of hashrefs defining the columns expected to be in the file.
my $defs = [ $converter->column_defs ];
Now $defs could look like:
[ { name => 'Number',
internal => 'id',
},
{ name => 'Frequency' },
{ name => 'group',
in => sub {...},
out => sub {...},
},
...,
];
The in filter is used by "read" to convert to the internal
conversion format.
do_something($row) unless $converter->is_empty_row($row);
Takes a parsed row hashref and returns truthy if it is an "empty" row.
A hashref of additional parameters to be passed to the "csv" in Text::CSV call.
This allows subclasses to adjust the parameters passed to "new" in Text::CSV to control the output of the file.
The default is eol => "\r\n", quote_space => 0.
This boolean indicates whether we should write out the header line in the CSV file.
This is a boolean that indicates whether this file type supports extra columns or whether they are ignored.
Defaults to the value of "write_headers".
A boolean value that indicates whether the empty rows should be included when writing.
my $internal_name = $converter->internal_header( $external_name );
Looks up the internal header name from the format specific name.
Also caches the conversion to enable "external_header" lookups.
Does this normally by checking the "column_defs" for a matching name
and returning the internal version if it exists.
Otherwise does some basic conversions to make the headers more
friendly to use in perl.
Currently the conversions are:
- Convert to lowercase.
- transmit -> tx
- receive -> rx
- frequency -> freq
- Replace non-word characters to underscores.
my $external_name = $converter->external_header( $internal_name );
If the "internal_name" has been calculated, looks up the external name from the cache. Otherwise throws an exception.
my $filter = $converter->filter_for( in => $internal_header );
Returns a filter, or undef if none exists, for the column, looked
up in "column_defs".
Likely a lot.
Perl 5.16 or higher.
Andrew Hewus Fresh [email protected]
This software is Copyright (c) 2021 by Andrew Hewus Fresh [email protected].
This is free software, licensed under:
The MIT (X11) License