Class: Arkrb::Mods
- Inherits:
-
Object
- Object
- Arkrb::Mods
- Defined in:
- lib/arkrb/server/mods.rb
Instance Method Summary collapse
- #add(id) ⇒ Arkrb::Mod, Exception
- #delete(id) ⇒ True, Exception
- #find_by_id(id) ⇒ Arkrb::Mod, Exception
-
#initialize ⇒ Mods
constructor
A new instance of Mods.
- #to_h ⇒ Hash (also: #to_hash)
Constructor Details
#initialize ⇒ Mods
Returns a new instance of Mods.
5 6 7 |
# File 'lib/arkrb/server/mods.rb', line 5 def initialize @mod_list = [] end |
Instance Method Details
#add(id) ⇒ Arkrb::Mod, Exception
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/arkrb/server/mods.rb', line 20 def add(id) begin find_by_id(id) raise Arkrb::Error::ModAlreadyExists, "Mod #{id} already exists in the mod list!" rescue Arkrb::Error::ModIDNotFound mod = Arkrb::Mod.new(id) @mod_list << mod mod end end |
#delete(id) ⇒ True, Exception
32 33 34 35 36 |
# File 'lib/arkrb/server/mods.rb', line 32 def delete(id) find_by_id(id) @mod_list.delete_if {|m| m.id == id} true end |
#find_by_id(id) ⇒ Arkrb::Mod, Exception
10 11 12 13 14 15 16 17 |
# File 'lib/arkrb/server/mods.rb', line 10 def find_by_id(id) mod = @mod_list.find {|m| m.id == id} if mod.nil? raise Arkrb::Error::ModIDNotFound, "Mod #{id} was not found in the mod list!" else mod end end |
#to_h ⇒ Hash Also known as: to_hash
39 40 41 |
# File 'lib/arkrb/server/mods.rb', line 39 def to_h @mod_list.map {|m| m.to_h} end |