Class: ModOrganizer::Mod

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Includes:
Utils
Defined in:
lib/mod_organizer/mod.rb

Overview

Object storing information about a mod a giving a lazy API on it to save resources (API calls, IO reading, files parsing, esp/bsa exploration…) A mod is an entry in ModOrganizer list.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#files_glob

Constructor Details

#initialize(mod_organizer, mod_path) ⇒ Mod

Constructor

Parameters
  • mod_organizer (ModOrganizer): The Mod Organizer instance this mod has been instantiated for

  • mod_path (String): Directory containing the mod information



22
23
24
25
26
# File 'lib/mod_organizer/mod.rb', line 22

def initialize(mod_organizer, mod_path)
  @mod_organizer = mod_organizer
  @path = mod_path
  @name = File.basename(@path)
end

Instance Attribute Details

#nameObject (readonly)

String: Mod’s name



15
16
17
# File 'lib/mod_organizer/mod.rb', line 15

def name
  @name
end

Instance Method Details

#categoriesObject

Return the list of ModOrganizer categories this mod belongs to

Result
  • Array<String>: List of MO categories



40
41
42
43
44
45
# File 'lib/mod_organizer/mod.rb', line 40

def categories
  meta_ini['General']['category'].to_s.split(',').map do |cat_id|
    cat_int = Integer(cat_id)
    cat_int.positive? ? @mod_organizer.categories[cat_int] : nil
  end.compact
end

#enabled?Boolean

Is this mod enabled in Mod Organizer?

Result
  • Boolean: Is this mod enabled in Mod Organizer?

Returns:

  • (Boolean)


32
33
34
# File 'lib/mod_organizer/mod.rb', line 32

def enabled?
  @mod_organizer.enabled_mods.include?(@name)
end

#pluginsObject

Return the list of plugins this mod is containing. Cache it.

Result
  • Array<String>: List of plugins belonging to this mod



52
53
54
55
56
57
58
# File 'lib/mod_organizer/mod.rb', line 52

def plugins
  (
    files_glob("#{@path}/*.esm") +
    files_glob("#{@path}/*.esp") +
    files_glob("#{@path}/*.esl")
  ).map { |file_name| File.basename(file_name).downcase }
end

#sourcesObject

Return the list of sources this mod belongs to

Result
  • Array<Source>: List of source information



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/mod_organizer/mod.rb', line 65

def sources
  nbr_sources = meta_ini['installedFiles']['size'] || 1
  nbr_sources.times.map do |install_idx|
    Source.new(
      @mod_organizer,
      nexus_mod_id: meta_ini['installedFiles']["#{install_idx + 1}\\modid"],
      nexus_file_id: meta_ini['installedFiles']["#{install_idx + 1}\\fileid"],
      file_name: install_idx == nbr_sources - 1 ? meta_ini['General']['installationFile'] : nil
    )
  end
end

#urlObject

The mod’s URL

Result
  • String or nil: The mod’s URL, or nil if none



82
83
84
85
# File 'lib/mod_organizer/mod.rb', line 82

def url
  ini_url = meta_ini['General']['url']
  ini_url.nil? || ini_url.empty? ? nil : ini_url
end