Class: MojangApi::Whitelist::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/mojang_api/whitelist/base.rb

Direct Known Subclasses

OneSeven, OneSix

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(profiles = []) ⇒ Base

Returns a new instance of Base.



6
7
8
# File 'lib/mojang_api/whitelist/base.rb', line 6

def initialize(profiles = [])
  @profiles = profiles
end

Instance Attribute Details

#profilesObject (readonly)

Returns the value of attribute profiles.



4
5
6
# File 'lib/mojang_api/whitelist/base.rb', line 4

def profiles
  @profiles
end

Class Method Details

.load_from(filename) ⇒ Object



37
38
39
40
41
# File 'lib/mojang_api/whitelist/base.rb', line 37

def load_from(filename)
  instance = new
  instance.load_from(filename)
  instance
end

Instance Method Details

#load_from(filename) ⇒ Object



10
11
12
13
14
15
# File 'lib/mojang_api/whitelist/base.rb', line 10

def load_from(filename)
  f = File.open(filename, "r")
  parse f
  f.close
  self
end

#save_to(filename) ⇒ Object



21
22
23
# File 'lib/mojang_api/whitelist/base.rb', line 21

def save_to(filename)
  File.open(filename, "w") { |f| f.write(serialize) }
end

#to_sObject



17
18
19
# File 'lib/mojang_api/whitelist/base.rb', line 17

def to_s
  serialize
end

#to_version(version) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/mojang_api/whitelist/base.rb', line 25

def to_version(version)
  case version
  when :v16
    OneSix.new(@profiles.dup)
  when :v17
    OneSeven.new(@profiles.dup)
  else
    raise "No such version!"
  end
end