class CraftingTable::Search::ItemIDSearch
A class which allows to filter recipes and items by their item ID.
@author Michael Senn <morrolan@morrolan.ch> @since 0.3
Attributes
item_id[R]
Public Class Methods
new(item_id)
click to toggle source
Create a new ItemIDSearch
@param [Fixnum, Range] item_id
Item
ID for which to search.
# File lib/crafting_table/search/item_id_search.rb, line 17 def initialize(item_id) @item_id = item_id end
Public Instance Methods
==(other)
click to toggle source
Compare two searches for equality.
They are considered equal if the item ID for which they filter is equal.
@param [ItemIDSearch] other ItemIDSearch
which to compare for equality. @return [Boolean] Whether two searches are equal.
# File lib/crafting_table/search/item_id_search.rb, line 41 def ==(other) other.item_id == item_id end
Also aliased as: eq?
apply_to(items)
click to toggle source
Apply this filter to a collection of items.
@param [Array<Item>] items
Collection of items which to filter.
@return [Array<Item>]
Items which matched the search criteria
# File lib/crafting_table/search/item_id_search.rb, line 27 def apply_to(items) if item_id.respond_to?(:include?) items.select { |item| item_id.include? item.item_id } else items.select { |item| item_id == item.item_id } end end