Class: Gooby::Line

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

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(raw = '', delim = nil, strip = false) ⇒ Line

Returns a new instance of Line.



15
16
17
18
19
20
21
22
23
# File 'lib/gooby_line.rb', line 15

def initialize(raw='', delim=nil, strip=false)
  if strip
    @raw_data = raw.strip
  else
    @raw_data = raw
  end
  
  @tokens   = tokenize(@raw_data, delim, strip=false)  
end

Instance Attribute Details

#raw_dataObject

Returns the value of attribute raw_data.



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

def raw_data
  @raw_data
end

#tokensObject

Returns the value of attribute tokens.



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

def tokens
  @tokens
end

Instance Method Details

#concatinate_tokens(start_idx = 0) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/gooby_line.rb', line 64

def concatinate_tokens(start_idx = 0)
  s = ''
  idx = -1
  @tokens.each { |tok| 
    idx = idx + 1
    if idx >= start_idx
      s << tok
      s << ' '
    end
  }
  s.strip!
  s
end

#is_commentObject



48
49
50
51
# File 'lib/gooby_line.rb', line 48

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

#is_populated_non_commentObject



53
54
55
56
57
58
59
60
61
62
# File 'lib/gooby_line.rb', line 53

def is_populated_non_comment
  s = @raw_data.strip
  if s.size == 0
    return false
  end
  if is_comment
    return false
  end
  return true   
end

#match(pattern) ⇒ Object



44
45
46
# File 'lib/gooby_line.rb', line 44

def match(pattern)
  @raw_data.match(pattern)
end

#token(idx) ⇒ Object



27
28
29
# File 'lib/gooby_line.rb', line 27

def token(idx)
  @tokens[idx]
end

#token_countObject



31
32
33
# File 'lib/gooby_line.rb', line 31

def token_count
  @tokens.size
end

#token_idx_equals(idx, value) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/gooby_line.rb', line 35

def token_idx_equals(idx, value)
  if idx < token_count
    if @tokens[idx] == value
      return true
    end
  end
  false
end