data

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AllRowsCsvRecordPredicate = func(r CsvRecord) bool {
	return true
}

AllRowsCsvRecordPredicate is an always true condition. All rows will be processed

View Source
var RowsWithoutIDsCsvRecordPredicate = func(r CsvRecord) bool {
	return r.ID == ""
}

RowsWithoutIDsCsvRecordPredicate filters rows with IDs. Only rows without IDs will be processed

View Source
var TodaysRowsCsvRecordPredicate = func(r CsvRecord) bool {
	startedTs, err := time.Parse(config.DefaultDateTimePattern, r.StartedTs)
	if err != nil {
		log.Fatalln("Error in TodaysRowsCsvRecordPredicate:", err)
	}

	return startedTs.Format(config.DefaultDatePattern) == time.Now().Format(config.DefaultDatePattern)
}

TodaysRowsCsvRecordPredicate filters rows with startedTs = today

Functions

This section is empty.

Types

type CsvFile

type CsvFile struct {
	Path    string
	Header  CsvHeader
	Records CsvRecords
}

CsvFile represents a CSV file with header and records. Use Read() and Write() to read and write data from/to disk

func NewCsvFile

func NewCsvFile(path string) CsvFile

NewCsvFile creates a new CsvFile with the given path and default header

func (*CsvFile) AddRecord

func (f *CsvFile) AddRecord(rec CsvRecord)

AddRecord adds (appends) a given record

func (*CsvFile) Read

func (f *CsvFile) Read(recordFilter CsvRecordPredicate)

ReadAll reads CSV file from disk with records which satisfy recordFilter predicate. Records, not matching the predicate will not be added to CsvFile.Records

func (*CsvFile) ReadAll

func (f *CsvFile) ReadAll()

ReadAll reads CSV file from disk with all records

func (*CsvFile) UpdateRecord

func (f *CsvFile) UpdateRecord(idx int, rec CsvRecord) error

UpdateRecord replaces record at the given index with the new record.

func (*CsvFile) Write

func (f *CsvFile) Write()

type CsvHeader

type CsvHeader []string

CsvHeader represents header in a CSV file

func GetCsvHeader

func GetCsvHeader() CsvHeader

GetCsvHeader returns a CSV-header row

type CsvRecord

type CsvRecord struct {
	ID        string
	StartedTs string
	Comment   string
	// TimeSpent string `validate:"required"`
	// Ticket    string `validate:"required"`
	TimeSpent string `validate:"required,timespent"`
	Ticket    string `validate:"required,jiraticket"`
	Category  string
	// contains filtered or unexported fields
}

CsvRecord represents a single record in a CSV file

func NewCsvRecord

func NewCsvRecord(rec []string) (CsvRecord, error)

NewCsvRecord created a new CsvRecord from a slice representing a single CSV row

func (*CsvRecord) AsRow

func (r *CsvRecord) AsRow() []string

AsRow represents a CSV-writable row

func (*CsvRecord) GetIdx

func (r *CsvRecord) GetIdx() int

GetIdx returns a row's index in CSV file

func (*CsvRecord) IsPushed

func (r *CsvRecord) IsPushed() bool

IsPushed returns true is the item has been already pushed to Jira server

type CsvRecordPredicate

type CsvRecordPredicate func(CsvRecord) bool

CsvRecordPredicate used as a condition for rows filtering when reading CSV file

type CsvRecords

type CsvRecords []CsvRecord

CsvRecords is a wrapper on []CsvRecord

func (*CsvRecords) AsRows

func (recs *CsvRecords) AsRows() [][]string

AsRows converts CsvRecords into 2-d slice representing CSV {records X columns}

func (*CsvRecords) Filter

func (recs *CsvRecords) Filter(recordFilter CsvRecordPredicate) CsvRecords

Filter returns a copy of records, filtered using the given recordFilter

Jump to

Keyboard shortcuts

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