class Gm::Notepad::TableEntry::Base

Constants

NUMBER_RANGE_REGEXP

Attributes

cells[R]
index[R]

Public Class Methods

new(*args) click to toggle source
Calls superclass method
# File lib/gm/notepad/table_entry.rb, line 25
def initialize(*args)
  super
  row = line.split(column_delimiter)
  self.index = row.shift
  self.cells = row
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/gm/notepad/table_entry.rb, line 33
def <=>(other)
  to_str <=> String(other)
end
entry() click to toggle source
# File lib/gm/notepad/table_entry.rb, line 59
def entry
  cells.join("\t")
end
Also aliased as: entry_column, to_str
entry_column()
Alias for: entry
lookup(cell:) click to toggle source
# File lib/gm/notepad/table_entry.rb, line 37
def lookup(cell:)
  index = table.column_index_for(cell: cell)
  if index.nil?
    # In the file, we have cell 0 is the index. This is hidden from the cell lookup, so I
    # want to internally treat the given cell as one less.
    cells[cell.to_i - 1]
  else
    cells[index] || cells[0]
  end
end
lookup_range() click to toggle source
# File lib/gm/notepad/table_entry.rb, line 49
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_s() click to toggle source
# File lib/gm/notepad/table_entry.rb, line 64
def to_s
  "[#{index}]\t#{entry}"
end
to_str()
Alias for: entry

Private Instance Methods

cells=(input) click to toggle source
# File lib/gm/notepad/table_entry.rb, line 75
def cells=(input)
  @cells = Array(input).map { |i| i.strip.freeze }.freeze
end
index=(input) click to toggle source
# File lib/gm/notepad/table_entry.rb, line 71
def index=(input)
  @index = input.strip.downcase.freeze
end