Class: Lich::Gemstone::Disk
- Inherits:
-
Object
- Object
- Lich::Gemstone::Disk
- Defined in:
- documented/gemstone/disk.rb
Overview
Represents a disk item in the game.
This class provides methods to identify, find, and manage disk objects.
Constant Summary collapse
- NOUNS =
%w{cassone chest coffer coffin coffret disk hamper saucer sphere trunk tureen}
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
-
.all ⇒ Array<Lich::Gemstone::Disk>
Retrieves all disk objects from the loot.
-
.find_by_name(name) ⇒ Lich::Gemstone::Disk?
Finds a disk by its name.
-
.is_disk?(thing) ⇒ Boolean
Checks if the given object is a disk based on its name.
-
.mine ⇒ Lich::Gemstone::Disk?
Mines for a disk based on the character's name.
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) ⇒ void
constructor
Initializes a new Disk object with the given game object.
- #method_missing(method, *args) ⇒ Object
-
#to_container ⇒ Container, GameObj
Converts this disk to a container object.
Constructor Details
#initialize(obj) ⇒ void
Initializes a new Disk object with the given game object.
53 54 55 56 57 58 |
# File 'documented/gemstone/disk.rb', line 53 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
74 75 76 |
# File 'documented/gemstone/disk.rb', line 74 def method_missing(method, *args) GameObj[@id].send(method, *args) end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
48 49 50 |
# File 'documented/gemstone/disk.rb', line 48 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
48 49 50 |
# File 'documented/gemstone/disk.rb', line 48 def name @name end |
Class Method Details
.all ⇒ Array<Lich::Gemstone::Disk>
Retrieves all disk objects from the loot.
40 41 42 43 44 45 46 |
# File 'documented/gemstone/disk.rb', line 40 def self.all() (GameObj.loot || []).select do |item| is_disk?(item) end.map do |i| Disk.new(i) end end |
.find_by_name(name) ⇒ Lich::Gemstone::Disk?
Finds a disk by its name.
24 25 26 27 28 29 30 |
# File 'documented/gemstone/disk.rb', line 24 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.
15 16 17 |
# File 'documented/gemstone/disk.rb', line 15 def self.is_disk?(thing) thing.name =~ /\b([A-Z][a-z]+) #{Regexp.union(NOUNS)}\b/ end |
.mine ⇒ Lich::Gemstone::Disk?
Mines for a disk based on the character's name.
34 35 36 |
# File 'documented/gemstone/disk.rb', line 34 def self.mine find_by_name(Char.name) end |
Instance Method Details
#==(other) ⇒ Boolean
Compares this disk with another disk for equality.
63 64 65 |
# File 'documented/gemstone/disk.rb', line 63 def ==(other) other.is_a?(Disk) && other.id == self.id end |
#eql?(other) ⇒ Boolean
Checks if this disk is equal to another disk.
70 71 72 |
# File 'documented/gemstone/disk.rb', line 70 def eql?(other) self == other end |
#to_container ⇒ Container, GameObj
Converts this disk to a container object.
80 81 82 83 84 85 86 |
# File 'documented/gemstone/disk.rb', line 80 def to_container if defined?(Container) Container.new(@id) else GameObj["#{@id}"] end end |