Class: CraftingTable::Search::DamageSearch
- Inherits:
-
Object
- Object
- CraftingTable::Search::DamageSearch
- Defined in:
- lib/crafting_table/search/damage_search.rb
Overview
A class which allows to filter recipes and items by their damage value.
Instance Attribute Summary collapse
- #damage_value ⇒ Object readonly
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eq?)
Compare two searches for equality.
-
#apply_to(items) ⇒ Array<Item>
Apply this filter to a collection of items.
-
#initialize(damage_value) ⇒ DamageSearch
constructor
Create a new DamageSearch.
Constructor Details
#initialize(damage_value) ⇒ DamageSearch
Create a new DamageSearch
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_value ⇒ Object (readonly)
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.
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.
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 |