Class: Arkrb::Mods

Inherits:
Object
  • Object
show all
Defined in:
lib/arkrb/server/mods.rb

Instance Method Summary collapse

Constructor Details

#initializeMods

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

Returns:



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

Returns:

  • (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

Returns:



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_hHash Also known as: to_hash

Returns:

  • (Hash)


39
40
41
# File 'lib/arkrb/server/mods.rb', line 39

def to_h
  @mod_list.map {|m| m.to_h}
end