Class: Gm::Notepad::TableEntry
- Inherits:
-
Object
- Object
- Gm::Notepad::TableEntry
- Extended by:
- Dry::Initializer
- 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
-
#cells ⇒ Object
readonly
Returns the value of attribute cells.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #entry ⇒ Object (also: #entry_column, #to_str)
-
#initialize(*args) ⇒ TableEntry
constructor
A new instance of TableEntry.
- #lookup(cell:) ⇒ Object
- #lookup_range ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(*args) ⇒ TableEntry
Returns a new instance of TableEntry.
13 14 15 16 17 18 |
# File 'lib/gm/notepad/table_entry.rb', line 13 def initialize(*args) super row = line.split(column_delimiter) self.index = row.shift self.cells = row end |
Instance Attribute Details
#cells ⇒ Object
Returns the value of attribute cells.
39 40 41 |
# File 'lib/gm/notepad/table_entry.rb', line 39 def cells @cells end |
#index ⇒ Object
Returns the value of attribute index.
39 40 41 |
# File 'lib/gm/notepad/table_entry.rb', line 39 def index @index end |
Instance Method Details
#<=>(other) ⇒ Object
21 22 23 |
# File 'lib/gm/notepad/table_entry.rb', line 21 def <=>(other) to_str <=> String(other) end |
#entry ⇒ Object Also known as: entry_column, to_str
41 42 43 |
# File 'lib/gm/notepad/table_entry.rb', line 41 def entry cells.join("\t") end |
#lookup(cell:) ⇒ Object
25 26 27 28 |
# File 'lib/gm/notepad/table_entry.rb', line 25 def lookup(cell:) index = table.column_index_for(cell: cell) cells[index] || cells[0] end |
#lookup_range ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/gm/notepad/table_entry.rb', line 31 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 ⇒ Object
46 47 48 |
# File 'lib/gm/notepad/table_entry.rb', line 46 def to_s "[#{index}]\t#{entry}" end |