Class: Gm::Notepad::Table
- Inherits:
-
Object
- Object
- Gm::Notepad::Table
- Extended by:
- Dry::Initializer
- Defined in:
- lib/gm/notepad/table.rb
Instance Method Summary collapse
- #all ⇒ Object
- #append(line:, write: false) ⇒ Object
- #column_index_for(cell:) ⇒ Object
- #column_names ⇒ Object
- #grep(expression) ⇒ Object
-
#initialize(*args) ⇒ Table
constructor
A new instance of Table.
- #lookup(index: false, cell: false) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Table
16 17 18 19 20 |
# File 'lib/gm/notepad/table.rb', line 16 def initialize(*args) super set_null_table_column_set! process(lines: lines) end |
Instance Method Details
#all ⇒ Object
34 35 36 |
# File 'lib/gm/notepad/table.rb', line 34 def all @table.values.uniq end |
#append(line:, write: false) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/gm/notepad/table.rb', line 56 def append(line:, write: false) process(lines: [line]) return unless filename return unless write File.open(filename, "a") do |file| file.puts(line) end end |
#column_index_for(cell:) ⇒ Object
42 43 44 |
# File 'lib/gm/notepad/table.rb', line 42 def column_index_for(cell:) @table_column_set.column_index_for(cell: cell) end |
#column_names ⇒ Object
38 39 40 |
# File 'lib/gm/notepad/table.rb', line 38 def column_names @table_column_set.names end |
#grep(expression) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/gm/notepad/table.rb', line 46 def grep(expression) returning_value = [] @table.each_value do |entry| if expression.match(entry.entry_column) returning_value << entry end end returning_value end |
#lookup(index: false, cell: false) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/gm/notepad/table.rb', line 22 def lookup(index: false, cell: false) if index && cell lookup_entry_by(index: index).lookup(cell: cell) elsif index lookup_entry_by(index: index) elsif cell lookup_random_entry.lookup(cell: cell) else lookup_random_entry end end |