Class: Gooby::CsvPoint

Inherits:
Point show all
Defined in:
lib/gooby_csv_point.rb

Instance Attribute Summary collapse

Attributes inherited from Point

#altitude, #latitude, #longitude, #note, #number

Instance Method Summary collapse

Methods inherited from Point

#altitude_as_float, #csv_delim, #deg2rad, #english_system, #has_coordinates?, #heartbeat_as_float, #initialize_from_array, #initialize_from_string, #latitude_as_float, #longitude_as_float, #metric_system, #proximity, #rad2deg, #to_csv

Methods included from GoobyKernel

#character_align, #default_delimiter, #invalid_altitude, #invalid_heartbeat, #invalid_latitude, #invalid_longitude, #invalid_time, #project_author, #project_copyright, #project_date, #project_embedded_comment, #project_license, #project_name, #project_version_number, #project_year, #read_as_ascii_lines, #read_lines, #strip_lines, #tokenize

Constructor Details

#initialize(csv_line) ⇒ CsvPoint

Returns a new instance of CsvPoint.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/gooby_csv_point.rb', line 18

def initialize(csv_line)
  @rawdata = "#{csv_line}"
  @tokens  = @rawdata.split(csv_delim)
  if (@tokens.size > 14)
    @id           = @tokens[0]  # <-- consists of @run_id.@tkpt_num for uniqueness and use as a DB table primary key.
    @run_id       = @tokens[1]
    @date         = @tokens[2]
    @time         = @tokens[3]
    @tkpt_num     = @tokens[4].strip.to_i
    @latitude     = @tokens[5].to_f
    @longitude    = @tokens[6].to_f 
    @altitude     = @tokens[7].strip.to_f 
    @heartbeat    = @tokens[8].strip.to_f         
    @distance     = @tokens[9].strip.to_f 
    @uom          = @tokens[10].strip
    @elapsed      = @tokens[11]
    @lap_number   = @tokens[12].strip.to_i 
    @lap_distance = @tokens[13].strip.to_f                                                     
    @lap_elapsed  = @tokens[14]
  end
end

Instance Attribute Details

#course_distanceObject

Returns the value of attribute course_distance.



16
17
18
# File 'lib/gooby_csv_point.rb', line 16

def course_distance
  @course_distance
end

#course_elapsedObject

Returns the value of attribute course_elapsed.



16
17
18
# File 'lib/gooby_csv_point.rb', line 16

def course_elapsed
  @course_elapsed
end

#dateObject (readonly)

Returns the value of attribute date.



14
15
16
# File 'lib/gooby_csv_point.rb', line 14

def date
  @date
end

#degrees_diffObject

Returns the value of attribute degrees_diff.



16
17
18
# File 'lib/gooby_csv_point.rb', line 16

def degrees_diff
  @degrees_diff
end

#distanceObject (readonly)

Returns the value of attribute distance.



14
15
16
# File 'lib/gooby_csv_point.rb', line 14

def distance
  @distance
end

#elapsedObject (readonly)

Returns the value of attribute elapsed.



14
15
16
# File 'lib/gooby_csv_point.rb', line 14

def elapsed
  @elapsed
end

#idObject (readonly)

Returns the value of attribute id.



14
15
16
# File 'lib/gooby_csv_point.rb', line 14

def id
  @id
end

#lap_distanceObject (readonly)

Returns the value of attribute lap_distance.



15
16
17
# File 'lib/gooby_csv_point.rb', line 15

def lap_distance
  @lap_distance
end

#lap_elapsedObject (readonly)

Returns the value of attribute lap_elapsed.



15
16
17
# File 'lib/gooby_csv_point.rb', line 15

def lap_elapsed
  @lap_elapsed
end

#lap_numberObject (readonly)

Returns the value of attribute lap_number.



15
16
17
# File 'lib/gooby_csv_point.rb', line 15

def lap_number
  @lap_number
end

#rawdataObject (readonly)

Returns the value of attribute rawdata.



13
14
15
# File 'lib/gooby_csv_point.rb', line 13

def rawdata
  @rawdata
end

#run_idObject (readonly)

Returns the value of attribute run_id.



14
15
16
# File 'lib/gooby_csv_point.rb', line 14

def run_id
  @run_id
end

#timeObject (readonly)

Returns the value of attribute time.



14
15
16
# File 'lib/gooby_csv_point.rb', line 14

def time
  @time
end

#tkpt_numObject (readonly)

Returns the value of attribute tkpt_num.



14
15
16
# File 'lib/gooby_csv_point.rb', line 14

def tkpt_num
  @tkpt_num
end

#tokensObject (readonly)

Returns the value of attribute tokens.



13
14
15
# File 'lib/gooby_csv_point.rb', line 13

def tokens
  @tokens
end

#uomObject (readonly)

Returns the value of attribute uom.



14
15
16
# File 'lib/gooby_csv_point.rb', line 14

def uom
  @uom
end

Instance Method Details

#as_trackpointObject



44
45
46
47
48
49
50
# File 'lib/gooby_csv_point.rb', line 44

def as_trackpoint
  tkpt = Trackpoint.new(@tkpt_num,  @latitude, @longitude, @altitude, @heartbeat, "#{date}T#{time}Z", @uom)
  tkpt.lap_number   = @lap_number
  tkpt.lap_distance = @lap_distance
  tkpt.lap_elapsed  = @lap_elapsed
  tkpt
end

#to_formatted_stringObject



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/gooby_csv_point.rb', line 56

def to_formatted_string
  s =  "lat: #{@latitude.to_s.ljust(20)}"
  s << " lng: #{@longitude.to_s.ljust(20)}"
  s << " time:            #{@time}"
  pad = ''.ljust(70)
  s << "\n#{pad} course elapsed:  #{@course_elapsed}"
  s << "\n#{pad} distance:        #{@distance}"
  s << "\n#{pad} heartbeat:       #{@heartbeat}" if (@heartbeat && (@heartbeat.to_f > 0))
  s << "\n#{pad} course distance: #{@course_distance}"
  s << "\n#{pad} altitude:        #{@altitude}"
  s << "\n#{pad} degrees diff:    #{@degrees_diff}"
  s
end

#to_sObject



52
53
54
# File 'lib/gooby_csv_point.rb', line 52

def to_s
  return "lat: #{@latitude} lng: #{@longitude} alt: #{@altitude} note: #{@note}"
end

#token_countObject



40
41
42
# File 'lib/gooby_csv_point.rb', line 40

def token_count
  @tokens ? @tokens.size : 0
end