Class: Gooby::DelimLine

Inherits:
GoobyObject show all
Defined in:
lib/gooby_delim_line.rb

Overview

Instances of this class represent a delimited line of text, such as csv.

Instance Attribute Summary collapse

Instance Method Summary collapse

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(line, trim = true, delim = default_delimiter) ⇒ DelimLine

Returns a new instance of DelimLine.



19
20
21
22
23
24
25
26
27
# File 'lib/gooby_delim_line.rb', line 19

def initialize(line, trim=true, delim=default_delimiter)
  @line   = line
  @trim   = trim
  @delim  = delim
  @tokens = @line.split(@delim)  
  if trim
    @tokens.each { | token | token.strip! }
  end
end

Instance Attribute Details

#delimObject (readonly)

Returns the value of attribute delim.



17
18
19
# File 'lib/gooby_delim_line.rb', line 17

def delim
  @delim
end

#lineObject (readonly)

Returns the value of attribute line.



17
18
19
# File 'lib/gooby_delim_line.rb', line 17

def line
  @line
end

#tokensObject (readonly)

Returns the value of attribute tokens.



17
18
19
# File 'lib/gooby_delim_line.rb', line 17

def tokens
  @tokens
end

#trimObject (readonly)

Returns the value of attribute trim.



17
18
19
# File 'lib/gooby_delim_line.rb', line 17

def trim
  @trim
end

Instance Method Details

#as_trackpoint(num_idx, lat_idx, lng_idx, alt_idx, dttm_idx) ⇒ Object



29
30
31
# File 'lib/gooby_delim_line.rb', line 29

def as_trackpoint(num_idx, lat_idx, lng_idx, alt_idx, dttm_idx)
  Trackpoint.new(@tokens[num_idx], @tokens[lat_idx], @tokens[lng_idx], @tokens[alt_idx], @tokens[dttm_idx])
end

#is_comment?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/gooby_delim_line.rb', line 33

def is_comment?
  @line.strip.match('^#') ? true : false
end

#to_sObject



37
38
39
# File 'lib/gooby_delim_line.rb', line 37

def to_s
  "DelimLine: length: #{@line.size} trim: #{@trim} delim: #{@delim} tokens: #{@tokens.size}"
end