class CraftingTable::Search::DamageSearch

A class which allows to filter recipes and items by their damage value.

@author Michael Senn <morrolan@morrolan.ch> @since 0.3

Attributes

damage_value[R]

Public Class Methods

new(damage_value) click to toggle source

Create a new DamageSearch

@param [Fixnum, Range] damage_value Damage value for which to filter.

# File lib/crafting_table/search/damage_search.rb, line 17
def initialize(damage_value)
  @damage_value = damage_value
end

Public Instance Methods

==(other) click to toggle source

Compare two searches for equality.

They are considered equal if the damage value for which they filter is equal.

@param [DamageSearch] other DamageSearch which to compare for equality. @return [Boolean] Whether two searches are equal.

# File lib/crafting_table/search/damage_search.rb, line 41
def ==(other)
  other.damage_value == damage_value
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/damage_search.rb, line 27
def apply_to(items)
  if damage_value.respond_to?(:include?)
    items.select { |item| damage_value.include? item.damage_value }
  else
    items.select { |item| damage_value == item.damage_value }
  end
end
eq?(other)
Alias for: ==