Class: Gm::Notepad::TableEntry

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/gm/notepad/table_entry.rb

Constant Summary collapse

NUMBER_RANGE_REGEXP =
%r{(?<left>\d+) *- *(?<right>\d+)}

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cellsObject

Returns the value of attribute cells.



31
32
33
# File 'lib/gm/notepad/table_entry.rb', line 31

def cells
  @cells
end

#indexObject

Returns the value of attribute index.



31
32
33
# File 'lib/gm/notepad/table_entry.rb', line 31

def index
  @index
end

Instance Method Details

#<=>(other) ⇒ Object



13
14
15
# File 'lib/gm/notepad/table_entry.rb', line 13

def <=>(other)
  to_str <=> String(other)
end

#entryObject Also known as: entry_column, to_str



33
34
35
# File 'lib/gm/notepad/table_entry.rb', line 33

def entry
  cells.join("\t")
end

#lookup(cell:) ⇒ Object



17
18
19
20
# File 'lib/gm/notepad/table_entry.rb', line 17

def lookup(cell:)
  # TODO: Need to deal with named columns
  cells[cell.to_i]
end

#lookup_rangeObject



23
24
25
26
27
28
29
# File 'lib/gm/notepad/table_entry.rb', line 23

def lookup_range
  if match = NUMBER_RANGE_REGEXP.match(index)
    (match[:left].to_i..match[:right].to_i).map(&:to_s)
  else
    [index]
  end
end

#to_sObject



38
39
40
# File 'lib/gm/notepad/table_entry.rb', line 38

def to_s
  "[#{index}]\t#{entry}"
end