Class: Gm::Notepad::TableEntry::Base
- Inherits:
-
Object
- Object
- Gm::Notepad::TableEntry::Base
- 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) ⇒ Base
constructor
A new instance of Base.
- #lookup(cell:) ⇒ Object
- #lookup_range ⇒ Object
- #to_s ⇒ Object
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
#cells ⇒ Object
Returns the value of attribute cells.
51 52 53 |
# File 'lib/gm/notepad/table_entry.rb', line 51 def cells @cells end |
#index ⇒ Object
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 |
#entry ⇒ Object 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_range ⇒ Object
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_s ⇒ Object
58 59 60 |
# File 'lib/gm/notepad/table_entry.rb', line 58 def to_s "[#{index}]\t#{entry}" end |