Class: Lich::Gemstone::Disk
- Inherits:
-
Object
- Object
- Lich::Gemstone::Disk
- Defined in:
- lib/gemstone/disk.rb
Overview
Represents a disk item in the game.
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<Disk>
Retrieves all disk objects from the loot.
-
.find_by_name(name) ⇒ Disk?
Finds a disk by its name.
-
.is_disk?(thing) ⇒ Boolean
Checks if the given object is a disk based on its name.
-
.mine ⇒ Disk?
Mines a disk based on the character’s name.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Compares this Disk object with another for equality.
-
#eql?(other) ⇒ Boolean
Checks if this Disk object is equal to another.
-
#initialize(obj) ⇒ Disk
constructor
Initializes a new Disk object.
-
#method_missing(method, *args) ⇒ Object
Handles missing methods by delegating to the GameObj.
-
#to_container ⇒ Container, Object
Converts the Disk object to a container.
Constructor Details
#initialize(obj) ⇒ Disk
Initializes a new Disk object.
61 62 63 64 65 66 |
# File 'lib/gemstone/disk.rb', line 61 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 missing methods by delegating to the GameObj.
95 96 97 |
# File 'lib/gemstone/disk.rb', line 95 def method_missing(method, *args) GameObj[@id].send(method, *args) end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
53 54 55 |
# File 'lib/gemstone/disk.rb', line 53 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
53 54 55 |
# File 'lib/gemstone/disk.rb', line 53 def name @name end |
Class Method Details
.all ⇒ Array<Disk>
Retrieves all disk objects from the loot.
45 46 47 48 49 50 51 |
# File 'lib/gemstone/disk.rb', line 45 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?
Finds a disk by its name.
23 24 25 26 27 28 29 |
# File 'lib/gemstone/disk.rb', line 23 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.
13 14 15 |
# File 'lib/gemstone/disk.rb', line 13 def self.is_disk?(thing) thing.name =~ /\b([A-Z][a-z]+) #{Regexp.union(NOUNS)}\b/ end |
.mine ⇒ Disk?
Mines a disk based on the character’s name.
36 37 38 |
# File 'lib/gemstone/disk.rb', line 36 def self.mine find_by_name(Char.name) end |
Instance Method Details
#==(other) ⇒ Boolean
Compares this Disk object with another for equality.
74 75 76 |
# File 'lib/gemstone/disk.rb', line 74 def ==(other) other.is_a?(Disk) && other.id == self.id end |
#eql?(other) ⇒ Boolean
Checks if this Disk object is equal to another.
84 85 86 |
# File 'lib/gemstone/disk.rb', line 84 def eql?(other) self == other end |
#to_container ⇒ Container, Object
This method depends on the existence of the Container class.
Converts the Disk object to a container.
105 106 107 108 109 110 111 |
# File 'lib/gemstone/disk.rb', line 105 def to_container if defined?(Container) Container.new(@id) else GameObj["#{@id}"] end end |