Class: Gm::Notepad::Table

Inherits:
Object
  • Object
show all
Defined in:
lib/gm/notepad/table.rb

Instance Method Summary collapse

Instance Method Details

#allObject



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

def all
  @table.values.uniq
end

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



33
34
35
36
37
38
39
40
# File 'lib/gm/notepad/table.rb', line 33

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

#grep(expression) ⇒ Object



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

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) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/gm/notepad/table.rb', line 11

def lookup(index: false)
  if index
    @table.fetch(index)
  else
    @table.values[random_index]
  end
end