Sha256: 4c96e882798bae5825ee8d844254795fdccfccb9fb878ee132a39ecafc4adebd

Contents?: true

Size: 747 Bytes

Versions: 1

Compression:

Stored size: 747 Bytes

Contents

require 'item_list_printer'

class List
  attr_reader :items

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

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

  def remove(item)
    fail '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.select { |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.1 lib/list.rb