@@ -21,7 +21,7 @@ type Vehicle struct {
2121 Vehicles []VehicleRecord `section:"VEHICLE"`
2222 FuelRecords []FuelRecord `section:"FUEL RECORDS"`
2323 MaintenanceRecords []MaintenanceRecord `section:"MAINTENANCE RECORDS"`
24- RoadTrips [] RoadTripRecord `section:"ROAD TRIPS"`
24+ Trips [] TripRecord `section:"ROAD TRIPS"`
2525 Tires []TireRecord `section:"TIRE LOG"`
2626 Valuations []ValuationRecord `section:"VALUATIONS"`
2727 Raw []byte
@@ -58,37 +58,43 @@ func (v *Vehicle) LoadFile(filename string) error {
5858 v .Raw = buf
5959 }
6060
61- if err := v .Parse ("FUEL RECORDS" , & v .FuelRecords ); err != nil {
62- return fmt .Errorf ("FuelRecords: %w" , err )
61+ err = v .Parse ("FUEL RECORDS" , & v .FuelRecords )
62+ if err != nil {
63+ return fmt .Errorf ("unable to parse FuelRecords: %w" , err )
6364 }
6465
65- if err := v .Parse ("MAINTENANCE RECORDS" , & v .MaintenanceRecords ); err != nil {
66+ err = v .Parse ("MAINTENANCE RECORDS" , & v .MaintenanceRecords )
67+ if err != nil {
6668 return fmt .Errorf ("MaintenanceRecords: %w" , err )
6769 }
6870
69- if err := v .Parse ("ROAD TRIPS" , & v .RoadTrips ); err != nil {
70- return fmt .Errorf ("RoadTrips: %w" , err )
71+ err = v .Parse ("ROAD TRIPS" , & v .Trips )
72+ if err != nil {
73+ return fmt .Errorf ("unable to parse Trips: %w" , err )
7174 }
7275
73- if err := v .Parse ("VEHICLE" , & v .Vehicles ); err != nil {
74- return fmt .Errorf ("Vehicle: %w" , err )
76+ err = v .Parse ("VEHICLE" , & v .Vehicles )
77+ if err != nil {
78+ return fmt .Errorf ("unable to parse Vehicle: %w" , err )
7579 }
7680
77- if err := v .Parse ("TIRE LOG" , & v .Tires ); err != nil {
78- return fmt .Errorf ("TireLogs: %w" , err )
81+ err = v .Parse ("TIRE LOG" , & v .Tires )
82+ if err != nil {
83+ return fmt .Errorf ("unable to parse TireLogs: %w" , err )
7984 }
8085
81- if err := v .Parse ("VALUATIONS" , & v .Valuations ); err != nil {
82- return fmt .Errorf ("Valuations: %w" , err )
86+ err = v .Parse ("VALUATIONS" , & v .Valuations )
87+ if err != nil {
88+ return fmt .Errorf ("unable to parse Valuations: %w" , err )
8389 }
8490
85- slog .Info ("Loaded Road Trip CSV" ,
91+ slog .Debug ("Loaded Road Trip CSV" ,
8692 "filename" , v .Filename ,
8793 "bytes" , len (buf ),
8894 "vehicleRecords" , len (v .Vehicles ),
8995 "fuelRecords" , len (v .FuelRecords ),
9096 "mainteanceRecords" , len (v .MaintenanceRecords ),
91- "roadTrips " , len (v .RoadTrips ),
97+ "Trips " , len (v .Trips ),
9298 "tireLogs" , len (v .Tires ),
9399 "valuations" , len (v .Valuations ),
94100 )
@@ -98,15 +104,15 @@ func (v *Vehicle) LoadFile(filename string) error {
98104
99105// Section returns a byte slice containing the raw contents of the specified section
100106// from the corresponding [CSV] object.
101- func (v * Vehicle ) Section (sectionHeader string ) ( outbuf []byte ) {
107+ func (v * Vehicle ) Section (sectionHeader string ) []byte {
102108 slog .Debug ("Fetching Section from Raw" ,
103109 "sectionHeader" , sectionHeader ,
104110 )
105111
106112 sectionStart := make (map [string ]int )
107113
108- for index , element := range Sections {
109- i := bytes .Index (v .Raw , []byte (Sections [index ]))
114+ for index , element := range SectionHeaders {
115+ i := bytes .Index (v .Raw , []byte (SectionHeaders [index ]))
110116 sectionStart [element ] = i
111117
112118 slog .Debug ("Section Start detected" ,
@@ -127,7 +133,7 @@ func (v *Vehicle) Section(sectionHeader string) (outbuf []byte) {
127133 // Don't include the section header line in the outbuf
128134 startPosition = startPosition + len (sectionHeader ) + 1
129135
130- outbuf = v .Raw [startPosition :endPosition ]
136+ outbuf : = v .Raw [startPosition :endPosition ]
131137
132138 slog .Debug ("Section Range calculated" ,
133139 "sectionHeader" , sectionHeader ,
@@ -136,7 +142,7 @@ func (v *Vehicle) Section(sectionHeader string) (outbuf []byte) {
136142 "sectionBytes" , len (outbuf ),
137143 )
138144
139- return
145+ return outbuf
140146}
141147
142148// Parse unmarshalls the raw byte slice of the specified section from the underlying [CSV]
@@ -150,8 +156,8 @@ func (v *Vehicle) Parse(sectionHeader string, target interface{}) error {
150156}
151157
152158// ParseDate parses a Road Trip styled date string and turns it into a proper
153- // Go [time.Time] value
154- func ParseDate (dateString string ) ( t time.Time ) {
159+ // Go [time.Time] value.
160+ func ParseDate (dateString string ) time.Time {
155161 t , err := time .Parse ("2006-1-2 15:04" , dateString )
156162 if err != nil {
157163 t , err = time .Parse ("2006-1-2" , dateString )
0 commit comments