parsers

package
v0.0.0-...-111d394 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2018 License: MIT Imports: 11 Imported by: 1

Documentation

Index

Constants

View Source
const DrexelUName string = "Drexel University"

DrexelUName holds the Drexel University's name

Variables

View Source
var ErrReportNotParsed error = errors.New("report has not been parsed")

ErrReportNotParsed is the error returned when a Parser has not been parsed yet

View Source
var ErrReportParsed error = errors.New("report already parsed")

ErrReportParsed is the error returned when a Parser has already parsed a report

Functions

This section is empty.

Types

type DrexelParser

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

DrexelParser implements the Parser interface for Drexel University Clery crime logs

func NewDrexelParser

func NewDrexelParser(geoCache *geo.GeoCache, fields []string) *DrexelParser

NewDrexelParser creates a new DrexelParser instance

func (DrexelParser) Count

func (p DrexelParser) Count() (uint, error)

Count returns the number of crimes parsed in the report.

func (*DrexelParser) Parse

func (p *DrexelParser) Parse(reportID int) ([]models.Crime, error)

Parse interprets a pdf's text fields into Crime structs. For the style of report Drexel University releases.

func (*DrexelParser) Range

func (p *DrexelParser) Range() (*time.Time, *time.Time, error)

Range implements the Range method for Parser. It parses the fields far enough to determine the date range the report covers

type Parser

type Parser interface {
	// Parse takes the text fields saved in the implementing struct and
	// parses them into a slice of Crime structs.
	//
	// A Report ID is provided to the Parse method. Which is the ID of the
	// Report which these crimes belong to.
	//
	// Additionally an error is returned, nil on success.
	Parse(reportID int) ([]models.Crime, error)

	// Range returns the date range which the report covers crimes for.
	// Start time, then end time. Along with an error if one occurs, or nil
	// on success.
	//
	// The parse method is expected to be called before Range(). And an
	// error will be returned if it has not been.
	Range() (*time.Time, *time.Time, error)

	// Count returns the number of Crime models parsed from a report. An
	// error is returned if one occurs. Nil on success.
	Count() (uint, error)
}

Parser provides methods for converting a stream of pdf text fields to Crime structs. This allows multiple different formats of reports to parsed.

type Reader

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

Reader takes in a Pdf file, and extracts crimes from it. Using the appropriate parser, based on the header.

func NewReader

func NewReader(path string, geoCache *geo.GeoCache) *Reader

NewReader creates a new Reader struct with the given file path.

func (Reader) Crimes

func (r Reader) Crimes() ([]models.Crime, bool)

Crimes returns the crimes recorded in the specified Clery report. Along with a boolean indicating if the report has been parsed yet

func (Reader) IsParsed

func (r Reader) IsParsed() bool

IsParsed indicates if the specified pdf file has been parsed for crimes yet

func (*Reader) Parse

func (r *Reader) Parse() ([]models.Crime, error)

Parse interprets a crime report file and returns the contained crimes. Additionally an error will be returned, nil on success.

Jump to

Keyboard shortcuts

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