Class: Flox::ResourceEnumerator

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/flox/resource_enumerator.rb

Overview

A helper class that stores the paths to a number of REST resources and supports iterating over those resources, downloading them lazily from the server.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rest_service, paths) ⇒ ResourceEnumerator

Returns a new instance of ResourceEnumerator.

Parameters:

  • rest_service (RestService)

    the service instance used to download the resources.

  • paths (Array<String>)

    the URLs to the resources that need to be accessed, relative to the game's root.



19
20
21
22
# File 'lib/flox/resource_enumerator.rb', line 19

def initialize(rest_service, paths)
  @service = rest_service
  @paths = paths
end

Instance Attribute Details

#lengthFixnum

Returns the total number of objects being enumerated.

Returns:

  • (Fixnum)

    the total number of objects being enumerated.



40
41
42
# File 'lib/flox/resource_enumerator.rb', line 40

def length
  @paths.length
end

Instance Method Details

#eachObject

Iterates over the resources provided on intialization, loading them from the server one by one.



26
27
28
29
30
# File 'lib/flox/resource_enumerator.rb', line 26

def each
  @paths.each do |path|
    yield @service.get(path)
  end
end