class Boom::List

Attributes

items[RW]

Public: lets you access the array of items contained within this List.

Returns an Array of Items.

name[RW]

Public: the name of the List.

Returns the String name.

Public Class Methods

delete(name) click to toggle source

Public: deletes a List by name.

name - String name of the list to delete

Returns whether one or more lists were removed.

# File lib/boom/list.rb, line 62
def self.delete(name)
  previous = storage.lists.size
  storage.lists = storage.lists.reject { |list| list.name == name }
  previous != storage.lists.size
end
find(name) click to toggle source

Public: finds any given List by name.

name - String name of the list to search for

Returns the first instance of List that it finds.

# File lib/boom/list.rb, line 53
def self.find(name)
  storage.lists.find { |list| list.name == name } 
end
new(name) click to toggle source

Public: creates a new List instance in-memory.

name - The name of the List. Fails if already used.

Returns the unpersisted List instance.

# File lib/boom/list.rb, line 15
def initialize(name)
  @items = []
  @name  = name
end
storage() click to toggle source

Public: accesses the in-memory JSON representation.

Returns a Storage instance.

# File lib/boom/list.rb, line 23
def self.storage
  Boom.storage
end

Public Instance Methods

add_item(item) click to toggle source

Public: associates an Item with this List. If the item name is already defined, then the value will be replaced

item - the Item object to associate with this List.

Returns the current set of items.

# File lib/boom/list.rb, line 43
def add_item(item)
  delete_item(item.name) if find_item(item.name)
  @items << item
end
delete_item(name) click to toggle source

Public: deletes an Item by name.

name - String name of the item to delete

Returns whether an item was removed.

# File lib/boom/list.rb, line 73
def delete_item(name)
  previous = items.size
  items.reject! { |item| item.name == name}
  previous != items.size
end
find_item(name) click to toggle source

Public: finds an Item by name. If the name is typically truncated, also allow a search based on that truncated name.

name - String name of the Item to find

Returns the found item.

# File lib/boom/list.rb, line 85
def find_item(name)
  items.find do |item|
    item.name == name ||
    item.short_name.gsub('…','') == name.gsub('…','')
  end
end
to_hash() click to toggle source

Public: a Hash representation of this List.

Returns a Hash of its own data and its child Items.

# File lib/boom/list.rb, line 95
def to_hash
  { name => items.collect(&:to_hash) }
end