scp

package
v0.2.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 22, 2024 License: MIT Imports: 9 Imported by: 4

Documentation

Overview

Package scp provides access to the Super Check Partial (http://www.supercheckpartial.com) database stored in the SCP format. The package also provides functions to download, store and update a MASTER.SCP file. The default remote location for the MASTER.SCP file is http://www.supercheckpartial.com/MASTER.SCP.

File Format Description

1. The file is in plain text format (ASCII). 2. Each line contains one callsign. 3. Lines that begin with # are comments that can be ignored.

Index

Constants

View Source
const DefaultLocalFilename = ".config/hamradio/MASTER.SCP"

DefaultLocalFilename is the default name for the file that is used to store the contents of MASTER.SCP locally in the user's home directory.

View Source
const DefaultURL = "http://www.supercheckpartial.com/MASTER.SCP"

DefaultURL is the original URL of the MASTER.SCP file: http://www.supercheckpartial.com/MASTER.SCP

Variables

View Source
var DefaultFieldSet = NewFieldSet("Call", "Name", "Loc1", "Loc2", "Sect", "State", "CK", "BirthDate", "Exch1", "Misc", "UserText", "LastUpdateNote")

DefaultFieldSet defines the default field set that is used if no !!Order!! directive is present in the call history file.

View Source
var SCPFormat = EntryParserFunc(func(line string) (Entry, bool) {
	if strings.HasPrefix(line, "#") {
		return Entry{}, false
	}
	return newEntry(line, nil), true
})

Functions

func Download

func Download(remoteURL, localFilename string) error

Download downloads the database file from a remote URL and stores it locally.

func LocalFilename

func LocalFilename() (string, error)

LocalFilename returns the absolute path of the default local filename in the current user's home directory.

func Update

func Update(remoteURL, localFilename string) (bool, error)

Update updates the local copy of the database file from the given remote URL, but only if an update is needed.

Types

type CallHistoryParser added in v0.2.0

type CallHistoryParser struct {
	// contains filtered or unexported fields
}

CallHistoryParser is used to parse the entries in a call history file to fill the database.

func NewCallHistoryParser added in v0.2.0

func NewCallHistoryParser() *CallHistoryParser

NewCallHistoryParser creates a new CallHistoryParser that uses the DefaultFieldSet.

func (*CallHistoryParser) ParseEntry added in v0.2.0

func (p *CallHistoryParser) ParseEntry(line string) (Entry, bool)

ParseEntry parses the given line and returns the corresponding entry. If the line contains other information (for example a comment or a directive), this method returns false in the second return value.

type Database

type Database struct {
	// contains filtered or unexported fields
}

Database represents the SCP database.

func LoadLocal

func LoadLocal(localFilename string) (*Database, error)

LoadLocal loads the database from a file in the local filesystem.

func LoadRemote

func LoadRemote(remoteURL string) (*Database, error)

LoadRemote loads the database file from a remote URL.

func Read

func Read(r io.Reader, parser EntryParser) (*Database, error)

Read the database from a reader unsing the given entry parser.

func ReadCallHistory added in v0.2.0

func ReadCallHistory(r io.Reader) (*Database, error)

ReadCallHistory creates a new Database and fills it from the call history that is read with the given reader.

func ReadSCP added in v0.2.0

func ReadSCP(r io.Reader) (*Database, error)

Read the database from a reader using the SCP format.

func (Database) Find added in v0.2.0

func (database Database) Find(s string) ([]Match, error)

Find returns all entries in database that are similar to the given string.

func (Database) FindStrings

func (database Database) FindStrings(s string) ([]string, error)

FindStrings returns all strings in database that partially match the given string

type Entry added in v0.2.0

type Entry struct {
	// contains filtered or unexported fields
}

Entry represents one entry in a Database.

func (Entry) CompareTo added in v0.2.0

func (e Entry) CompareTo(o Entry) (distance, accuracy)

CompareTo compares this Entry's key with the key of the given Entry. It returns a measure of similarity in form of the editing distance and the matching accuracy.

func (Entry) EditTo added in v0.2.0

func (e Entry) EditTo(o Entry) (distance, accuracy, MatchingAssembly)

EditTo provides the editing distance, matching accuracy, and the given Entry's key as MatchingAssembly

func (Entry) Get added in v0.2.0

func (e Entry) Get(field FieldName) string

Get the value of the field with the given name.

func (Entry) GetValues added in v0.2.0

func (e Entry) GetValues(fields ...FieldName) []string

GetValues returns the values of the fields with the given names as slice. The returned slice is of the same size as the number of field names. If a field is not populated, the corresponding slice entry is empty.

func (Entry) Key added in v0.2.0

func (e Entry) Key() string

Key returns the key of this Entry.

func (Entry) PopulatedFields added in v0.2.0

func (e Entry) PopulatedFields() FieldSet

PopulatedFields returns a FieldSet that contains all populated fields of this Entry.

func (Entry) String added in v0.2.0

func (e Entry) String() string

type EntryParser added in v0.2.0

type EntryParser interface {
	ParseEntry(string) (Entry, bool)
}

EntryParser defines an abstraction for parsing a single entry from a given line in a file.

type EntryParserFunc added in v0.2.0

type EntryParserFunc func(string) (Entry, bool)

EntryParserFunc wraps a matching function into the EntryParser interface

func (EntryParserFunc) ParseEntry added in v0.2.0

func (f EntryParserFunc) ParseEntry(line string) (Entry, bool)

type FieldName added in v0.2.0

type FieldName string

FieldName defines the name of a field in an Entry.

const (
	FieldCall     FieldName = "Call"
	FieldUserName FieldName = "Name"
	FieldUserText FieldName = "UserText"
	FieldIgnore   FieldName = ""
)

type FieldSet added in v0.2.0

type FieldSet []FieldName

FieldSet defines a set of fields used in a call history file.

func NewFieldSet added in v0.2.0

func NewFieldSet(fieldNames ...string) FieldSet

NewFieldSet creates a new FieldSet with the given field names.

func (FieldSet) CallIndex added in v0.2.0

func (s FieldSet) CallIndex() int

CallIndex returns the index of the Call field.

func (FieldSet) Get added in v0.2.0

func (s FieldSet) Get(index int) FieldName

Get returns the field name at the given index.

func (FieldSet) IndexOf added in v0.2.0

func (s FieldSet) IndexOf(field FieldName) int

IndexOf returns the index of the field with the given name in this FieldSet, or -1 if the field is not in this FieldSet.

type FieldValues added in v0.2.0

type FieldValues map[FieldName]string

FieldValues contains all fields of an Entry and their corresponding values.

type Match added in v0.2.0

type Match struct {
	Entry

	Assembly MatchingAssembly
	// contains filtered or unexported fields
}

func (Match) Accuracy added in v0.2.1

func (m Match) Accuracy() float64

func (Match) LessThan added in v0.2.0

func (m Match) LessThan(o Match) bool

LessThan returns true if this match is less than the other based on the default ordering for matches (the better the lesser).

type MatchingAssembly added in v0.2.0

type MatchingAssembly []MatchingPart

MatchingAssembly describes how a certain key matches to another key, using editing operations.

func (MatchingAssembly) ContainsFalseFriend added in v0.2.1

func (m MatchingAssembly) ContainsFalseFriend() bool

ContainsFalseFriend indicates if this matching assembly contains a false friend.

func (MatchingAssembly) LongestPart added in v0.2.0

func (m MatchingAssembly) LongestPart() int

LongestPart returns the length of the longest matching part.

func (MatchingAssembly) String added in v0.2.0

func (m MatchingAssembly) String() string

type MatchingOperation added in v0.1.1

type MatchingOperation int

MatchingOperation represents an editing operation that is applied to a key to transform it into another key.

const (
	// NOP = no edit required, the part matches exactly
	NOP MatchingOperation = iota
	// Insert this part
	Insert
	// Delete this part
	Delete
	// Substitute this part
	Substitute
	// FalseFriend is a subsitute that is close in CW to this part
	FalseFriend
)

type MatchingPart added in v0.2.0

type MatchingPart struct {
	OP    MatchingOperation
	Value string
}

Part represents a part of a key with the corresponding editing operation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL