Class: CraftingTable::Search::DamageSearch

Inherits:
Object
  • Object
show all
Defined in:
lib/crafting_table/search/damage_search.rb

Overview

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

Since:

  • 0.3

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(damage_value) ⇒ DamageSearch

Create a new DamageSearch

Parameters:

  • damage_value (Fixnum, Range)

    Damage value for which to filter.

Since:

  • 0.3



17
18
19
# File 'lib/crafting_table/search/damage_search.rb', line 17

def initialize(damage_value)
  @damage_value = damage_value
end

Instance Attribute Details

#damage_valueObject (readonly)

Since:

  • 0.3



12
13
14
# File 'lib/crafting_table/search/damage_search.rb', line 12

def damage_value
  @damage_value
end

Instance Method Details

#==(other) ⇒ Boolean Also known as: eq?

Compare two searches for equality.

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

Parameters:

  • other (DamageSearch)

    DamageSearch which to compare for equality.

Returns:

  • (Boolean)

    Whether two searches are equal.

Since:

  • 0.3



41
42
43
# File 'lib/crafting_table/search/damage_search.rb', line 41

def ==(other)
  other.damage_value == damage_value
end

#apply_to(items) ⇒ Array<Item>

Apply this filter to a collection of items.

Parameters:

  • items (Array<Item>)

    Collection of items which to filter.

Returns:

  • (Array<Item>)

    Items which matched the search criteria

Since:

  • 0.3



27
28
29
30
31
32
33
# 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