Class: ItemBase

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

Direct Known Subclasses

Item, ItemClone

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(block, _parent = nil, _parent_association = nil) ⇒ ItemBase

Returns a new instance of ItemBase.



4
5
6
7
8
# File 'lib/item_base.rb', line 4

def initialize(block, _parent = nil, _parent_association = nil)
  @id = block.id
  @name = block.content.split(' || ')[0].underscore.singularize
  @twin_name = block.content.split(' || ')[1]&.underscore&.singularize
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



2
3
4
# File 'lib/item_base.rb', line 2

def id
  @id
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/item_base.rb', line 2

def name
  @name
end

#twin_nameObject

Returns the value of attribute twin_name.



2
3
4
# File 'lib/item_base.rb', line 2

def twin_name
  @twin_name
end

Class Method Details

.allObject



10
11
12
# File 'lib/item_base.rb', line 10

def self.all
  ObjectSpace.each_object(self).to_a
end

.find(id) ⇒ Object



14
15
16
# File 'lib/item_base.rb', line 14

def self.find(id)
  all.find { |item| item.id == id }
end