lender

package
v0.0.0-...-b7bc2db Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2015 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package lender contains the structure and logic for a lender type. Also contains functions for importing lenders

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FieldParseError

type FieldParseError struct {
	// Cause is the root cause of the parsing error.
	Cause error
	// LineNo is the line (row) that the error occurred on.
	LineNo int
	// Field is the name of the field where the error occurrd.
	Field string
}

FieldParseError is an error structure that is used when importing a csv file. A custom structure is used to provide additional information when debugging an import problem of a csv file.

func NewFieldParseError

func NewFieldParseError(lineNo int, field string, cause error) *FieldParseError

NewFieldParseError is a helper function for creating a field parse error. Returns a pointer to a new FieldParseError structure.

func (*FieldParseError) Error

func (l *FieldParseError) Error() string

The Error function is used to satisfy the error interface. Returns a string represntation of the FieldParseError.

type Lender

type Lender struct {
	Name      string
	Rate      float64
	Available int
}

Lender is a structure representing an individual lender.

func (*Lender) Borrow

func (l *Lender) Borrow(amount int) int

Borrow is a function used to determine how much a lender can lend. The amount is how much the requester wishes to borrow. Returns the amount the lender can borrow. This will be either the full amount if possible, or the maximum the lender has available if not.

type Lenders

type Lenders []Lender

Lenders represents a slice of lenders. The type also has methods to support sort interface

func ImportCSV

func ImportCSV(filename string) (Lenders, error)

ImportCSV is a function used to import a csv file located by filename, parse and convert to a Lenders slice of Lender structures. Returns a Lenders slice of lenders if successfully imported, or the assoicated error otherwise.

func (Lenders) Len

func (slice Lenders) Len() int

Len returns the size of the lender slice. Used to satisfy the sort interface.

func (Lenders) Less

func (slice Lenders) Less(i, j int) bool

Less compares the lender at index i to index j and determines which is less and therefore higher in the list. Used to satisfy the sort interface. Returns true if i should be ranked higher than j in the sort.

func (Lenders) Swap

func (slice Lenders) Swap(i, j int)

Swap switches the position of lender at index i with lender at index j in the slice. Used to satisfy the sort interface.

Jump to

Keyboard shortcuts

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