class Factorio::Mod

Info interface

example:

“` mod = Factorio::Mod.new 'LTN-easier' puts “The author of #{mod.title} is #{mod.author}” puts “The #{mod.title} is under #{mod.license}” puts “It latest version can download at #{mod.latest_download}” puts “It latest version for factorio 0.16 can download at ” \

"#{mod.latest_download('0.16')[:uri]}"

“`

Constants

API_URI
Download

store the entry of the download

MOD_URI

factorio Mod portal website URI

VERSION

Attributes

id[R]
name[R]
string_id[R]

Public Class Methods

exist?(name) click to toggle source

Get mod if exist.

@param name [String] name of the mod @return [Bool] is exist

# File lib/factorio/mod/mod.rb, line 81
def self.exist?(name)
  name = Addressable::URI.encode(name)
  URI.open(API_URI % name)
  true
rescue OpenURI::HTTPError
  false
end
extend_uri(rel) click to toggle source

Extend relative links to absolute links @param rel [String] relative link @return [String] absolute link @raise [NotLoginError]

# File lib/factorio/mod/mod.rb, line 93
def self.extend_uri(rel)
  Addressable::URI.join(MOD_URI, rel)
end
login(username, password) click to toggle source

Get the log in token by username and password.

@example

print 'username: '
user = gets.chomp
print 'password: '
pass = gets.chomp
token = Factorio::Mod.login user, pass

@param username [String] @param password [String] @return [String] The log in token

# File lib/factorio/mod/mod.rb, line 42
def self.login(username, password)
  data = Addressable::URI.form_encode(
    'username' => username,
    'password' => password,
  )
  result = Net::HTTP.post('https://auth.factorio.com/api-login', data)
                    .then(JSON.method(:parse))
  result.first
rescue OpenURI::HTTPError
  raise result['message']
end
name_from_card(card) click to toggle source

Get mod name from mod card.

@param card [Nokogiri::HTML] @return [String] The name in

# File lib/factorio/mod/mod.rb, line 58
def self.name_from_card(card)
  card.xpath('.//h2[@class="mod-card-title"]/a/@href').text \
      .split('/').last.then(&Addressable::URI.method(:unencode))
end
new(name) click to toggle source

@param name [String] name of the Mod

# File lib/factorio/mod/mod.rb, line 26
def initialize(name)
  @name = name
  @mod = Cache.new name
end

Public Instance Methods

author() click to toggle source

Get the author of the Mod. @return [String] author

# File lib/factorio/mod/mod.rb, line 139
def author
  @mod.get[:owner]
end
Also aliased as: owner
deprecated?() click to toggle source

Whether Mod is deprecated @return [Boolean] is deprecated

# File lib/factorio/mod/mod.rb, line 146
def deprecated?
  @mod.get[:deprecated] || false
end
display_name()
Alias for: title
download_list() click to toggle source

Get the download for all of version. @return [Array<Download>]

# File lib/factorio/mod/mod.rb, line 167
def download_list
  @mod.get[:releases].dup.map(&Download.method(:create))
end
download_times() click to toggle source

Get the totle number of downloads of Mod. @return [Integer] number of downloads

# File lib/factorio/mod/mod.rb, line 152
def download_times
  @mod.get[:downloads_count]
end
Also aliased as: downloads_count
downloads_count()
Alias for: download_times
git() click to toggle source

Get the git repo URI that can be cloned. @return [Addressable::URI] git URI

# File lib/factorio/mod/mod.rb, line 120
def git
  github&.to_s&.+('.git')&.then(&Addressable::URI.method(:parse))
end
github() click to toggle source

Get the GitHub URI. @return [Addressable::URI] GitHub URI

# File lib/factorio/mod/mod.rb, line 112
def github
  @mod.get[:github_path].presence&.then do
    Addressable::URI.join('https://github.com', _1)
  end
end
latest_download(version = nil, ifnone = nil) click to toggle source

Get the latest download of the Mod. @param version [String] factorio version @return [Download]

# File lib/factorio/mod/mod.rb, line 160
def latest_download(version = nil, ifnone = nil)
  version.blank? && download_list.last ||
    download_list.reverse.find(ifnone) { _1.game_version == version.to_s }
end
latest_download_uri() click to toggle source

Get latest download uri by download button in card @return [Addressable::URI] download uri

# File lib/factorio/mod/mod.rb, line 173
def latest_download_uri
  Mod.extend_uri(latest_download[:download_url])
end
Also aliased as: latest_download_link
license() click to toggle source

Get the license that the Mod use. @return [String] license name

# File lib/factorio/mod/mod.rb, line 126
def license
  @mod.get(:license, :name)
end
license_uri() click to toggle source

Get the license URI. @return [Addressable::URI] license URI

# File lib/factorio/mod/mod.rb, line 132
def license_uri
  Addressable::URI.parse(@mod.get(:license, :url))
end
Also aliased as: license_link
owner()
Alias for: author
summary() click to toggle source

Get the summary of the Mod @return [String] summary

# File lib/factorio/mod/mod.rb, line 106
def summary
  @mod.get[:summary]
end
title() click to toggle source

Get the title (also known as _display name_) of the Mod @return [String] title

# File lib/factorio/mod/mod.rb, line 99
def title
  @mod.get[:title]
end
Also aliased as: display_name