Module: Containers
- Defined in:
- lib/Olib/core/containers.rb
Class Method Summary collapse
- .[](name) ⇒ Object
- .define(name) ⇒ Object
- .find_game_obj!(pattern) ⇒ Object
- .left_hand ⇒ Object
- .method_missing(name, *args) ⇒ Object
- .registry ⇒ Object
- .right_hand ⇒ Object
Class Method Details
.[](name) ⇒ Object
40 41 42 43 |
# File 'lib/Olib/core/containers.rb', line 40 def self.[](name) return define(name) if name.is_a?(Symbol) find_game_obj!(name) end |
.define(name) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/Olib/core/containers.rb', line 33 def self.define(name) var = Vars[name.to_s] or fail Exception, "Var[#{name}] is not set\n\t;vars set #{name}=<whatever>" pattern = %r[#{var}] @@containers[name] = Containers.find_game_obj!(pattern) @@containers[name] end |
.find_game_obj!(pattern) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/Olib/core/containers.rb', line 6 def self.find_game_obj!(pattern) candidates = GameObj.inv.select do |item| if pattern.class.is_a?(String) item.name.include?(pattern) else item.name.match(pattern) end end case candidates.size when 1 return Container.new(candidates.first) when 0 fail Exception, <<~ERROR Source(GameObj.inv) reason: no matches for Pattern(#{pattern}) found in GameObj.inv ERROR else fail Exception, <<~ERROR Source(GameObj.inv) reason: aspecific Container[#{pattern.to_s}] found matches: #{candidates.map(&:name)} ERROR end end |
.left_hand ⇒ Object
49 50 51 |
# File 'lib/Olib/core/containers.rb', line 49 def self.left_hand Container.new(Char.left) end |
.method_missing(name, *args) ⇒ Object
57 58 59 60 |
# File 'lib/Olib/core/containers.rb', line 57 def self.method_missing(name, *args) return @@containers[name] if @@containers[name] return self.define(name) end |
.registry ⇒ Object
53 54 55 |
# File 'lib/Olib/core/containers.rb', line 53 def self.registry @@containers end |