Sha256: 6c3ecf1c114e6bf0ad5dcadedd0b595e454b918952d0869c72b0aaca192c615a

Contents?: true

Size: 756 Bytes

Versions: 1

Compression:

Stored size: 756 Bytes

Contents

require 'item_list_printer'

# List
class List
  attr_reader :items

  def initialize(items = [])
    @items = items
  end

  def add(item)
    raise 'Already exists in list' if found?(item)
    @items << item
    'Success'
  end

  def remove(item)
    raise 'Not found in list' unless found?(item)
    @items.delete(item)
    'Success'
  end

  def to_string(item_list_printer = ItemListPrinter)
    item_list_printer.to_string(all)
  end

  def to_summary(keys, item_list_printer = ItemListPrinter)
    item_list_printer.to_summary(all, keys)
  end

  def get_by_index(index)
    all[index]
  end

  def find(item)
    all.detect { |arr| arr == item }
  end

  private

  def found?(item)
    @items.include?(item)
  end

  def all
    @items
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
item_list-0.1.2 lib/list.rb