Class: Factorio::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/factorio/mod/cache.rb

Overview

Cache mod info

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, cookie = '') ⇒ Cache

Returns a new instance of Cache.

Parameters:

  • uri (String)

    Mod URI like https://mods.factorio.com/mod/LTN-easier



9
10
11
12
13
# File 'lib/factorio/mod/cache.rb', line 9

def initialize(uri, cookie = '')
  @uri = uri
  @cookie = cookie
  @cache = {}
end

Instance Attribute Details

#cacheObject (readonly)

Returns the value of attribute cache.



6
7
8
# File 'lib/factorio/mod/cache.rb', line 6

def cache
  @cache
end

Instance Method Details

#any(better = :information) ⇒ Nokogiri::HTML

Get any page that already downloads. Get better(default information) mod page if none of the pages exist.

Parameters:

  • better (Symbol) (defaults to: :information)

    get which page if none of the pages exist.

Returns:

  • (Nokogiri::HTML)


31
32
33
34
35
36
37
38
39
# File 'lib/factorio/mod/cache.rb', line 31

def any(better = :information)
  if @cache.key? better
    @cache[better]
  elsif @cache.any?
    @cache.first.second
  else
    public_method(better).call
  end
end

#downloadsNokogiri::HTML

Get the Downloads page.

Returns:

  • (Nokogiri::HTML)


23
24
25
# File 'lib/factorio/mod/cache.rb', line 23

def downloads
  get :downloads, "#{@uri}/downloads"
end

#informationNokogiri::HTML

Get the Information page.

Returns:

  • (Nokogiri::HTML)


17
18
19
# File 'lib/factorio/mod/cache.rb', line 17

def information
  get :information, @uri
end