Class: Factorio::Cache
- Inherits:
-
Object
- Object
- Factorio::Cache
- Defined in:
- lib/factorio/mod/cache.rb
Overview
Cache mod info
Constant Summary collapse
- PAGES =
%i[information downloads].freeze
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
Instance Method Summary collapse
-
#any(better = :information) ⇒ Nokogiri::HTML
Get any page that already downloads.
-
#downloads ⇒ Nokogiri::HTML
Get the
Downloads
page. -
#information ⇒ Nokogiri::HTML
Get the
Information
page. -
#initialize(name, cookie = '') ⇒ Cache
constructor
A new instance of Cache.
Constructor Details
#initialize(name, cookie = '') ⇒ Cache
Returns a new instance of Cache.
11 12 13 14 15 16 |
# File 'lib/factorio/mod/cache.rb', line 11 def initialize(name, = '') @name = name @uri = Addressable::URI.encode("mod/#{@name}") @cookie = @cache = {} end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
8 9 10 |
# File 'lib/factorio/mod/cache.rb', line 8 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.
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/factorio/mod/cache.rb', line 34 def any(better = :information) unless PAGES.include? better raise NoPageError, "page #{better.to_s.capitalize} not exist" end if @cache.key? better @cache[better] elsif @cache.any? @cache.first.second else public_method(better).call end end |