Class: Fable::ListDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/fable/list_definition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_valuesObject

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

#itemsObject

Returns the value of attribute items.



3
4
5
# File 'lib/fable/list_definition.rb', line 3

def items
  @items
end

#nameObject

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

Returns:

  • (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

Returns:

  • (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