Class: Lapis::Minecraft::Versioning::Manifest

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

Overview

Contains basic information about all known versions of Minecraft.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(versions, latest_release_id, latest_snapshot_id) ⇒ Manifest

Creates a new manifest with version instances.

Parameters:

  • versions (Array<Basic>)

    List of all versions.

  • latest_release_id (String)

    ID of the version for the latest release.

  • latest_snapshot_id (String)

    ID of the version for the latest snapshot.


21
22
23
24
25
# File 'lib/lapis/minecraft/versioning/manifest.rb', line 21

def initialize(versions, latest_release_id, latest_snapshot_id)
  @versions        = versions.dup.freeze
  @latest_release  = versions.find { |version| version.id == latest_release_id }
  @latest_snapshot = versions.find { |version| version.id == latest_snapshot_id }
end

Instance Attribute Details

#latest_releaseBasic (readonly)

Retrieves information about the latest release.

Returns:


11
12
13
# File 'lib/lapis/minecraft/versioning/manifest.rb', line 11

def latest_release
  @latest_release
end

#latest_snapshotBasic (readonly)

Retrieves information about the latest snapshot.

Returns:


15
16
17
# File 'lib/lapis/minecraft/versioning/manifest.rb', line 15

def latest_snapshot
  @latest_snapshot
end

Instance Method Details

#==(other) ⇒ true, false

Compares one manifest to another.

Parameters:

  • other (Manifest)

    Manifest to compare against.

Returns:

  • (true)

    The manifests are the same.

  • (false)

    The manifests are different.


50
51
52
53
54
# File 'lib/lapis/minecraft/versioning/manifest.rb', line 50

def ==(other)
  other.entries == @versions &&
      other.latest_release == @latest_release &&
      other.latest_snapshot == @latest_snapshot
end

#[](id) ⇒ Basic?

Retrieves version information given a specific ID.

Parameters:

  • id (String)

    ID of the version to retrieve.

Returns:

  • (Basic)

    Version information.

  • (nil)

    No version with the provided ID exists.


42
43
44
# File 'lib/lapis/minecraft/versioning/manifest.rb', line 42

def [](id)
  @versions.find { |version| version.id == id }
end

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

Iterates over all versions.

Yield Parameters:

  • version (Basic)

    Next version in the list.

Returns:


30
31
32
33
34
35
36
# File 'lib/lapis/minecraft/versioning/manifest.rb', line 30

def each
  return enum_for(:each) unless block_given?

  @versions.each do |version|
    yield version
  end
end