Class: Fable::ListDefinition
- Inherits:
-
Object
- Object
- Fable::ListDefinition
- Defined in:
- lib/fable/list_definition.rb
Instance Attribute Summary collapse
-
#item_name_to_values ⇒ Object
The main representation should be simple item names, rather than a RawListItem, since we mainly want to access items based on their simple name, since that’s how they’ll be most commonly requested from ink.
-
#items ⇒ Object
Returns the value of attribute items.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #contains?(item) ⇒ Boolean
- #contains_item_with_name?(item_name) ⇒ Boolean
-
#initialize(name, items) ⇒ ListDefinition
constructor
A new instance of ListDefinition.
- #item_for_value(int_value) ⇒ Object
- #value_for_item(item) ⇒ Object
Constructor Details
#initialize(name, items) ⇒ ListDefinition
Returns a new instance of ListDefinition.
39 40 41 42 |
# File 'lib/fable/list_definition.rb', line 39 def initialize(name, items) self.name = name self.item_name_to_values = items end |
Instance Attribute Details
#item_name_to_values ⇒ Object
The main representation should be simple item names, rather than a RawListItem, since we mainly want to access items based on their simple name, since that’s how they’ll be most commonly requested from ink
9 10 11 |
# File 'lib/fable/list_definition.rb', line 9 def item_name_to_values @item_name_to_values end |
#items ⇒ Object
Returns the value of attribute items.
3 4 5 |
# File 'lib/fable/list_definition.rb', line 3 def items @items end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/fable/list_definition.rb', line 3 def name @name end |
Instance Method Details
#contains?(item) ⇒ Boolean
26 27 28 29 |
# File 'lib/fable/list_definition.rb', line 26 def contains?(item) return false if item.origin_name != self.name return contains_item_with_name?(item.item_name) end |
#contains_item_with_name?(item_name) ⇒ Boolean
31 32 33 |
# File 'lib/fable/list_definition.rb', line 31 def contains_item_with_name?(item_name) return item_name_to_values.has_key?(item_name) end |
#item_for_value(int_value) ⇒ Object
35 36 37 |
# File 'lib/fable/list_definition.rb', line 35 def item_for_value(int_value) return item_name_to_values.key(int_value) end |
#value_for_item(item) ⇒ Object
22 23 24 |
# File 'lib/fable/list_definition.rb', line 22 def value_for_item(item) return item_name_to_values[item.item_name] || 0 end |