Class: Gm::Notepad::TableEntry::Base

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

Direct Known Subclasses

OrLess, OrMore

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Base

Returns a new instance of Base.



25
26
27
28
29
30
# 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

Instance Attribute Details

#cellsObject

Returns the value of attribute cells.



51
52
53
# File 'lib/gm/notepad/table_entry.rb', line 51

def cells
  @cells
end

#indexObject

Returns the value of attribute index.



51
52
53
# File 'lib/gm/notepad/table_entry.rb', line 51

def index
  @index
end

Instance Method Details

#<=>(other) ⇒ Object



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

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

#entryObject Also known as: entry_column, to_str



53
54
55
# File 'lib/gm/notepad/table_entry.rb', line 53

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

#lookup(cell:) ⇒ Object



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

def lookup(cell:)
  index = table.column_index_for(cell: cell)
  cells[index] || cells[0]
end

#lookup_rangeObject



43
44
45
46
47
48
49
# File 'lib/gm/notepad/table_entry.rb', line 43

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



58
59
60
# File 'lib/gm/notepad/table_entry.rb', line 58

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