Class: Lapis::Minecraft::Versioning::VersionList

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/lapis/minecraft/versioning/version_list.rb

Overview

Complete listing of Minecraft versions and detailed information about them.

Constant Summary collapse

OFFICIAL_MANIFEST_URL =

URL of the official Mojang Minecraft version list.

'https://launchermeta.mojang.com/mc/game/version_manifest.json'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(manifest_url) ⇒ VersionList

Creates a version list.

Parameters:

  • manifest_url (String)

    URL of the document listing all versions.


24
25
26
27
# File 'lib/lapis/minecraft/versioning/version_list.rb', line 24

def initialize(manifest_url)
  @manifest_url = manifest_url.dup.freeze
  @meta_server  = MetaServer.new(HTTPClient.new)
end

Class Method Details

.officialVersionList

Singleton for retrieving information about official Minecraft versions.

Returns:

  • (VersionList)

    Access to official version information.


18
19
20
# File 'lib/lapis/minecraft/versioning/version_list.rb', line 18

def self.official
  @official ||= new(OFFICIAL_MANIFEST_URL)
end

Instance Method Details

#[](id) ⇒ Version?

Retrieves version information given a specific ID.

Parameters:

  • id (String)

    ID of the version to retrieve.

Returns:

  • (Version)

    Version information.

  • (nil)

    No version with the provided ID exists.


44
45
46
47
48
49
50
# File 'lib/lapis/minecraft/versioning/version_list.rb', line 44

def [](id)
  if (basic = manifest[id])
    Version.new(basic, @meta_server)
  else
    nil
  end
end

#each {|version| ... } ⇒ Enumerator<Version>

Iterates over all versions.

Yield Parameters:

  • version (Version)

    Next version in the list.

Returns:


32
33
34
35
36
37
38
# File 'lib/lapis/minecraft/versioning/version_list.rb', line 32

def each
  return enum_for(:each) unless block_given?

  manifest.each do |basic|
    yield Version.new(basic, @meta_server)
  end
end

#latest_releaseVersion

Retrieves the latest released version.

Returns:

  • (Version)

    Version information.


54
55
56
# File 'lib/lapis/minecraft/versioning/version_list.rb', line 54

def latest_release
  Version.new(manifest.latest_release, @meta_server)
end

#latest_snapshotVersion

Information about the latest snapshot version.

Returns:

  • (Version)

    Version information.


60
61
62
# File 'lib/lapis/minecraft/versioning/version_list.rb', line 60

def latest_snapshot
  Version.new(manifest.latest_snapshot, @meta_server)
end