lib/gm/notepad/table.rb in gm-notepad-0.0.2 vs lib/gm/notepad/table.rb in gm-notepad-0.0.3

- old
+ new

@@ -1,12 +1,13 @@ -require_relative "exceptions" -require_relative "table_entry" +require "gm/notepad/exceptions" +require "gm/notepad/table_entry" module Gm module Notepad class Table - def initialize(table_name:, lines:, filename: nil) + def initialize(table_name:, lines:, filename: nil, **config) + self.config = config self.table_name = table_name self.filename = filename process(lines: lines) end @@ -17,11 +18,11 @@ @table.values[random_index] end end def all - @table.values + @table.values.uniq end def grep(expression) returning_value = [] @table.each_value do |entry| @@ -41,19 +42,19 @@ end end private - attr_accessor :table_name, :filename + attr_accessor :table_name, :filename, :config def random_index rand(@table.size) end def process(lines:) @table = {} lines.each do |line| - entry = TableEntry.new(line: line) + entry = TableEntry.new(line: line, **config) entry.lookup_range.each do |i| key = i.to_s raise DuplicateKeyError.new(key: table_name, object: self) if @table.key?(key) @table[key] = entry end