Class: Gm::Notepad::Table

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

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Table

Returns a new instance of Table.



16
17
18
19
20
21
# File 'lib/gm/notepad/table.rb', line 16

def initialize(*args)
  super
  @table = {}
  set_null_table_column_set!
  process(lines: lines)
end

Instance Method Details

#allObject



35
36
37
# File 'lib/gm/notepad/table.rb', line 35

def all
  @table.values.uniq
end

#append(line:, write: false) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/gm/notepad/table.rb', line 57

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



43
44
45
# File 'lib/gm/notepad/table.rb', line 43

def column_index_for(cell:)
  @table_column_set.column_index_for(cell: cell)
end

#column_namesObject



39
40
41
# File 'lib/gm/notepad/table.rb', line 39

def column_names
  @table_column_set.names
end

#grep(expression) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'lib/gm/notepad/table.rb', line 47

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



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/gm/notepad/table.rb', line 23

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