class Boom::List
Attributes
Public: lets you access the array of items contained within this List
.
Returns an Array of Items.
Public: the name of the List
.
Returns the String name.
Public Class Methods
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
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
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
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
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
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