Class: Lich::Gemstone::Disk
- Inherits:
-
Object
- Object
- Lich::Gemstone::Disk
- Defined in:
- documented/gemstone/disk.rb
Overview
Represents a disk object in the game. This class provides methods to identify, find, and manage disk objects.
Constant Summary collapse
- NOUNS =
A list of nouns that represent different types of disks.
%w{cassone chest coffer coffin coffret disk hamper saucer sphere trunk tureen}
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Provides read access to the disk’s ID and name.
-
#name ⇒ Object
readonly
Provides read access to the disk’s ID and name.
Class Method Summary collapse
-
.all ⇒ Array<Disk>
Retrieves all disk objects from the game’s loot.
-
.find_by_name(name) ⇒ Disk?
Finds a disk by its name in the game’s loot.
-
.is_disk?(thing) ⇒ Boolean
Checks if the given object is a disk based on its name.
-
.mine ⇒ Disk?
Mines the disk associated with the current character.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Compares this disk with another disk for equality.
-
#eql?(other) ⇒ Boolean
Checks if this disk is equal to another disk.
-
#initialize(obj) ⇒ Disk
constructor
Initializes a new Disk object with the given game object.
-
#method_missing(method, *args) ⇒ Object
Handles calls to methods that are not defined in this class.
-
#to_container ⇒ Container, GameObj
Converts this disk into a container object.
Constructor Details
#initialize(obj) ⇒ Disk
Initializes a new Disk object with the given game object.
67 68 69 70 71 72 |
# File 'documented/gemstone/disk.rb', line 67 def initialize(obj) @id = obj.id @name = obj.name.split(" ").find do |word| word[0].upcase.eql?(word[0]) end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
Handles calls to methods that are not defined in this class.
98 99 100 |
# File 'documented/gemstone/disk.rb', line 98 def method_missing(method, *args) GameObj[@id].send(method, *args) end |
Instance Attribute Details
#id ⇒ Object (readonly)
Provides read access to the disk’s ID and name.
59 60 61 |
# File 'documented/gemstone/disk.rb', line 59 def id @id end |
#name ⇒ Object (readonly)
Provides read access to the disk’s ID and name.
59 60 61 |
# File 'documented/gemstone/disk.rb', line 59 def name @name end |
Class Method Details
.all ⇒ Array<Disk>
Retrieves all disk objects from the game’s loot.
50 51 52 53 54 55 56 |
# File 'documented/gemstone/disk.rb', line 50 def self.all() (GameObj.loot || []).select do |item| is_disk?(item) end.map do |i| Disk.new(i) end end |
.find_by_name(name) ⇒ Disk?
This method searches through the game’s loot.
Finds a disk by its name in the game’s loot.
28 29 30 31 32 33 34 |
# File 'documented/gemstone/disk.rb', line 28 def self.find_by_name(name) disk = GameObj.loot.find do |item| is_disk?(item) && item.name.include?(name) end return nil if disk.nil? Disk.new(disk) end |
.is_disk?(thing) ⇒ Boolean
Checks if the given object is a disk based on its name.
17 18 19 |
# File 'documented/gemstone/disk.rb', line 17 def self.is_disk?(thing) thing.name =~ /\b([A-Z][a-z]+) #{Regexp.union(NOUNS)}\b/ end |
.mine ⇒ Disk?
Mines the disk associated with the current character.
41 42 43 |
# File 'documented/gemstone/disk.rb', line 41 def self.mine find_by_name(Char.name) end |
Instance Method Details
#==(other) ⇒ Boolean
Compares this disk with another disk for equality.
80 81 82 |
# File 'documented/gemstone/disk.rb', line 80 def ==(other) other.is_a?(Disk) && other.id == self.id end |
#eql?(other) ⇒ Boolean
Checks if this disk is equal to another disk.
87 88 89 |
# File 'documented/gemstone/disk.rb', line 87 def eql?(other) self == other end |
#to_container ⇒ Container, GameObj
Converts this disk into a container object.
107 108 109 110 111 112 113 |
# File 'documented/gemstone/disk.rb', line 107 def to_container if defined?(Container) Container.new(@id) else GameObj["#{@id}"] end end |