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
22
23
# File 'lib/gm/notepad/table.rb', line 16

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

Instance Method Details

#allObject



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

def all
  @table.values.uniq
end

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



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

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



45
46
47
# File 'lib/gm/notepad/table.rb', line 45

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

#column_namesObject



41
42
43
# File 'lib/gm/notepad/table.rb', line 41

def column_names
  @table_column_set.names
end

#grep(expression) ⇒ Object



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

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



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

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

#set_or_less_entry(table_entry) ⇒ Object



68
69
70
# File 'lib/gm/notepad/table.rb', line 68

def set_or_less_entry(table_entry)
  @or_less = table_entry
end

#set_or_more_entry(table_entry) ⇒ Object



72
73
74
# File 'lib/gm/notepad/table.rb', line 72

def set_or_more_entry(table_entry)
  @or_more = table_entry
end