Class: Gm::Notepad::Table
- Inherits:
-
Object
- Object
- Gm::Notepad::Table
- Defined in:
- lib/gm/notepad/table.rb
Instance Method Summary collapse
- #all ⇒ Object
- #append(line:, write: false) ⇒ Object
- #grep(expression) ⇒ Object
- #lookup(index: false) ⇒ Object
Instance Method Details
#all ⇒ Object
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 |