Module: RgssDb::Utilities
- Defined in:
- lib/rgss_db/model/utilities.rb
Overview
Utilities module
Constant Summary collapse
- INVALID_CHARACTERS =
Regular expression of invalid characters or sequence of characters
/[:*?"<>|]|(\bCON\b|\bPRN\b|\bAUX\b|\bNUL\b|\bCOM[1-9]\b|\bLPT[1-9]\b)/i
Class Method Summary collapse
-
.menu_default_indexes(options_menu, options_user, all_if_empty: false, &block) {|, , | ... } ⇒ Array<Integer>
Gets the list of the default (pre-selected) indexes for a TTY selection menu.
-
.valid_path?(path) ⇒ Boolean
Checks whether the path is valid or not.
-
.validate_path(path) ⇒ MatchData
Validates the path.
Class Method Details
.menu_default_indexes(options_menu, options_user, all_if_empty: false, &block) {|, , | ... } ⇒ Array<Integer>
Gets the list of the default (pre-selected) indexes for a TTY selection menu
If a block is given, it will be used to evaluate the index selection
The block receives the following parameters “[Object, Integer, Object]“:
- The first one is the current menu option being evaluated
- The second one is the index of the menu option being evaluated
- The third argument iterates through each user option
If the block ever returns “true“ for the current menu option, its index will be saved
If no block is given, it will use “Array#include?“ to check if either the menu option or the menu index exists in the options user list
The following flags can be used to alter the behavior:
- all_if_empty: Select all options if the user's options list is empty
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/rgss_db/model/utilities.rb', line 41 def self.(, , all_if_empty: false, &block) # Checks if user's options list is empty (and populate it with all indexes if allowed) return (1...size).to_a if .empty? && all_if_empty return [] if .empty? # Process the menu options list normally = [] if block_given? .each_with_index do |, index| = index + 1 << if .any? { |opt_user| yield , , opt_user } end else .each_with_index do |, index| = index + 1 << if .include?() || .include?() end end end |
.valid_path?(path) ⇒ Boolean
Checks whether the path is valid or not
Returns “true“ if the path is valid, otherwise “false“
86 87 88 |
# File 'lib/rgss_db/model/utilities.rb', line 86 def self.valid_path?(path) validate_path(path).nil? end |
.validate_path(path) ⇒ MatchData
Validates the path
Returns a “MatchData“ if the path is invalid, otherwise “nil“
The “MatchData“ object contains the invalid characters
73 74 75 |
# File 'lib/rgss_db/model/utilities.rb', line 73 def self.validate_path(path) path.to_s.match(INVALID_CHARACTERS) end |