Class: RgssDb::DataFile
- Inherits:
-
Object
- Object
- RgssDb::DataFile
- Includes:
- Comparable
- Defined in:
- lib/rgss_db/model/data_file.rb
Overview
RPG Maker base data file
This class saves the object as is, without any treatment
Direct Known Subclasses
Instance Attribute Summary collapse
-
#file_path ⇒ String
readonly
Data file path.
-
#object ⇒ Object
readonly
Data file object (not processed).
-
#object_ids ⇒ Array<Integer>
readonly
Data file object IDs list.
-
#type ⇒ String
readonly
Data file type.
Instance Method Summary collapse
-
#<=>(other) ⇒ Integer
Comparable operator (case insensitive).
-
#all_objects? ⇒ Boolean
Checks whether all objects are included in the serialization process.
-
#convert_list_to_ids(list) ⇒ Array<Integer>
Converts the given object list to object IDs for this data file.
-
#customizable? ⇒ Boolean
Checks whether this data file instance supports object selection or not.
-
#file ⇒ String
Gets the data file name.
-
#file?(file) ⇒ Boolean
Checks if the given file base name matches this data file base name.
-
#file_path?(file) ⇒ Boolean
Checks if the given file matches this data file path.
-
#initialize(type, file_path, object) ⇒ DataFile
constructor
Constructor.
-
#merge(data_file) ⇒ Object
Merges the given data file contents with this data file.
-
#mergeable? ⇒ Boolean
Checks whether this data file instance is mergeable or not.
-
#object_ids_clear ⇒ Object
Clears the current list of object IDs.
-
#object_ids_update(*object_ids) ⇒ Object
Updates the list of object IDs for this data file.
-
#serialize ⇒ Object
Serializes the data file’s object.
-
#serialize_file_name ⇒ String
Process the data file’s file name for serialization.
-
#to_list ⇒ Array<Object>
Gets a list of objects to perform a selection.
-
#to_merge ⇒ Array<Object>
Gets a list of objects prepared to be merged.
-
#to_s ⇒ String
Converts this instance to a string.
-
#type?(data_type) ⇒ Boolean
Checks if the given data type matches this data file type.
Constructor Details
#initialize(type, file_path, object) ⇒ DataFile
Constructor
103 104 105 106 107 108 |
# File 'lib/rgss_db/model/data_file.rb', line 103 def initialize(type, file_path, object) @type = type @file_path = file_path @object = object @object_ids = [] end |
Instance Attribute Details
#file_path ⇒ String (readonly)
Data file path
86 87 88 |
# File 'lib/rgss_db/model/data_file.rb', line 86 def file_path @file_path end |
#object ⇒ Object (readonly)
Data file object (not processed)
94 95 96 |
# File 'lib/rgss_db/model/data_file.rb', line 94 def object @object end |
#object_ids ⇒ Array<Integer> (readonly)
Data file object IDs list
90 91 92 |
# File 'lib/rgss_db/model/data_file.rb', line 90 def object_ids @object_ids end |
#type ⇒ String (readonly)
Data file type
82 83 84 |
# File 'lib/rgss_db/model/data_file.rb', line 82 def type @type end |
Instance Method Details
#<=>(other) ⇒ Integer
Comparable operator (case insensitive)
298 299 300 301 302 |
# File 'lib/rgss_db/model/data_file.rb', line 298 def <=>(other) return @file_path.downcase <=> other.file_path.downcase if other.is_a?(DataFile) @file_path.downcase <=> other.downcase if other.is_a?(String) end |
#all_objects? ⇒ Boolean
Checks whether all objects are included in the serialization process
172 173 174 |
# File 'lib/rgss_db/model/data_file.rb', line 172 def all_objects? true end |
#convert_list_to_ids(list) ⇒ Array<Integer>
Converts the given object list to object IDs for this data file
The given list must be instances of this data file’s contents
By default it returns an empty array
254 255 256 |
# File 'lib/rgss_db/model/data_file.rb', line 254 def convert_list_to_ids(list) [] end |
#customizable? ⇒ Boolean
Checks whether this data file instance supports object selection or not
154 155 156 |
# File 'lib/rgss_db/model/data_file.rb', line 154 def customizable? !to_list.nil? end |
#file ⇒ String
Gets the data file name
199 200 201 |
# File 'lib/rgss_db/model/data_file.rb', line 199 def file File.basename(@file_path) end |
#file?(file) ⇒ Boolean
Checks if the given file base name matches this data file base name
The check is case insensitive
132 133 134 |
# File 'lib/rgss_db/model/data_file.rb', line 132 def file?(file) File.basename(@file_path).casecmp?(File.basename(file)) end |
#file_path?(file) ⇒ Boolean
Checks if the given file matches this data file path
The check is case insensitive
119 120 121 |
# File 'lib/rgss_db/model/data_file.rb', line 119 def file_path?(file) @file_path.casecmp?(file) end |
#merge(data_file) ⇒ Object
Merges the given data file contents with this data file
226 227 228 |
# File 'lib/rgss_db/model/data_file.rb', line 226 def merge(data_file) raise "cannot merge data file: '#{data_file}' because it is not supported!" end |
#mergeable? ⇒ Boolean
Checks whether this data file instance is mergeable or not
163 164 165 |
# File 'lib/rgss_db/model/data_file.rb', line 163 def mergeable? !to_merge.nil? end |
#object_ids_clear ⇒ Object
Clears the current list of object IDs
190 191 192 |
# File 'lib/rgss_db/model/data_file.rb', line 190 def object_ids_clear @object_ids.clear end |
#object_ids_update(*object_ids) ⇒ Object
Updates the list of object IDs for this data file
Any duped ID is auto. removed from the list
183 184 185 |
# File 'lib/rgss_db/model/data_file.rb', line 183 def object_ids_update(*object_ids) @object_ids = object_ids.flatten.uniq end |
#serialize ⇒ Object
Serializes the data file’s object
This method performs the necessary logic to the object for serialization
By default, it returns the object as is
239 240 241 |
# File 'lib/rgss_db/model/data_file.rb', line 239 def serialize @object end |
#serialize_file_name ⇒ String
Process the data file’s file name for serialization
The extension is automatically removed
210 211 212 213 214 215 216 217 |
# File 'lib/rgss_db/model/data_file.rb', line 210 def serialize_file_name base_name = File.basename(@file_path, ".*") if all_objects? base_name else base_name.concat(DATA_FILE_CUSTOM_LABEL) end end |
#to_list ⇒ Array<Object>
Gets a list of objects to perform a selection
If the data file does not allow this behavior it returns “nil“
Returns “nil“ by default
278 279 280 |
# File 'lib/rgss_db/model/data_file.rb', line 278 def to_list nil end |
#to_merge ⇒ Array<Object>
Gets a list of objects prepared to be merged
Returns “nil“ by default
265 266 267 |
# File 'lib/rgss_db/model/data_file.rb', line 265 def to_merge nil end |
#to_s ⇒ String
Converts this instance to a string
287 288 289 |
# File 'lib/rgss_db/model/data_file.rb', line 287 def to_s File.basename(@file_path) end |
#type?(data_type) ⇒ Boolean
Checks if the given data type matches this data file type
The check is case insensitive
145 146 147 |
# File 'lib/rgss_db/model/data_file.rb', line 145 def type?(data_type) File.fnmatch(@type, data_type, File::FNM_CASEFOLD) end |