Class: ModOrganizer::Mod
- Inherits:
-
Object
- Object
- ModOrganizer::Mod
- 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
-
#name ⇒ Object
readonly
String: Mod’s name.
Instance Method Summary collapse
-
#categories ⇒ Object
Return the list of ModOrganizer categories this mod belongs to.
-
#enabled? ⇒ Boolean
Is this mod enabled in Mod Organizer?.
-
#initialize(mod_organizer, mod_path) ⇒ Mod
constructor
Constructor.
-
#plugins ⇒ Object
Return the list of plugins this mod is containing.
-
#sources ⇒ Object
Return the list of sources this mod belongs to.
-
#url ⇒ Object
The mod’s URL.
Methods included from Utils
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
#name ⇒ Object (readonly)
String: Mod’s name
15 16 17 |
# File 'lib/mod_organizer/mod.rb', line 15 def name @name end |
Instance Method Details
#categories ⇒ Object
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 ['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?
32 33 34 |
# File 'lib/mod_organizer/mod.rb', line 32 def enabled? @mod_organizer.enabled_mods.include?(@name) end |
#plugins ⇒ Object
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 |
#sources ⇒ Object
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 = ['installedFiles']['size'] || 1 nbr_sources.times.map do |install_idx| Source.new( @mod_organizer, nexus_mod_id: ['installedFiles']["#{install_idx + 1}\\modid"], nexus_file_id: ['installedFiles']["#{install_idx + 1}\\fileid"], file_name: install_idx == nbr_sources - 1 ? ['General']['installationFile'] : nil ) end end |
#url ⇒ Object
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 = ['General']['url'] ini_url.nil? || ini_url.empty? ? nil : ini_url end |