Class: GamesAndRpgParadise::Lpc::Geas::CharacterExclusion

Inherits:
Base
  • Object
show all
Includes:
GamesAndRpgParadise::Lpc
Defined in:
lib/games_and_rpg_paradise/lpc/geas/character_exclusion.rb

Overview

GamesAndRpgParadise::Lpc::Geas::CharacterExclusion

Constant Summary collapse

THIS_FILE =
#

THIS_FILE

#
__FILE__
N_ROWS =
#

N_ROWS

#
3

Constants included from GamesAndRpgParadise::Lpc

CHARACTERS_IN_GUILDS, CHARACTER_EXCLUSION_DATA, CHARS_PER_LINE, DEFAULT_NAME, FILE_CHARACTER_DATASET, FILE_GEAS_CHARACTER_EXCLUSION_DATA, GamesAndRpgParadise::Lpc::GEAS_CHARACTER_EXCLUSION_DATA, GamesAndRpgParadise::Lpc::GEAS_YAML, HASH_EXITS_EXPANDED, HASH_LPC_TO_RUBY, HASH_OPPOSITE_EXITS, N, PROJECT_BASE_DIRECTORY, RPG, SAVE_FILE

Constants included from Base::Extensions::Colours

Base::Extensions::Colours::ARRAY_AVAILABLE_KONSOLE_COLOURS

Constants included from CommonExtensions

CommonExtensions::CONTROL_C_CODE, CommonExtensions::N

Instance Method Summary collapse

Methods included from GamesAndRpgParadise::Lpc

add_lpc_comment, find_opposite_exit, parse_forum_dataset, project_base_dir?, #rev, #warn

Methods included from Base::Extensions::Colours

ecomment, #efancy, #eparse, #forestgreen, #gold, #grey, #lightblue, #mediumseagreen, #mediumslateblue, #peru, #rev, sdir, sfancy, #sfile, simp, #yellow

Methods included from Base::Extensions::CommandlineArguments

#commandline_arguments?, #filter_away_commandline_arguments, #first_argument?, #first_non_hyphened_argument?, #set_commandline_arguments

Methods included from CommonExtensions

#cat, #cd, #copy_file, #delete, #dirname_but_retains_the_trailing_slash, #disable_colours, #ensure_that_the_log_directory_exists, #esystem, #get_user_input, #infer_the_namespace, #is_on_roebe?, #log_dir?, #mkdir, #mkdir_then_cd_into_it, #mv, #namespace?, #opne, #opnn, #project_base_directory?, #project_image_directory?, #project_yaml_directory?, #rds, #register_sigint, #remove_this_directory, #rename_file, #reset_the_internal_hash, #return_pwd, #return_today, #touch_file, #wrap, #write_what_into

Constructor Details

#initialize(optional_character_name = nil, run_already = true) ⇒ CharacterExclusion

#

initialize

The first argument to this class should be the name of the character at hand.

#


50
51
52
53
54
55
56
57
58
59
# File 'lib/games_and_rpg_paradise/lpc/geas/character_exclusion.rb', line 50

def initialize(
    optional_character_name = nil,
    run_already             = true
  )
  reset
  set_name(
    optional_character_name
  )
  run if run_already
end

Instance Method Details

#check_whether_character_is_registered_or_notObject

#

check_whether_character_is_registered_or_not

We can only continue if the character is registered.

#


192
193
194
195
196
197
198
199
200
201
# File 'lib/games_and_rpg_paradise/lpc/geas/character_exclusion.rb', line 192

def check_whether_character_is_registered_or_not
  if @registered_names.include? @name
  else
    e 'Sorry, the character '+teal(@name)+' is '+
      RED+'not included'+rev+' in our dataset.'
    e 'Perhaps you meant one of these instead?'
    report_possible_matches
    exit # Exit when we have not found a matching name.
  end
end

#clinerObject

#

cliner

#


242
243
244
# File 'lib/games_and_rpg_paradise/lpc/geas/character_exclusion.rb', line 242

def cliner
  e '='*80
end

#feedback_all_available_charactersObject

#

feedback_all_available_characters

#


206
207
208
209
# File 'lib/games_and_rpg_paradise/lpc/geas/character_exclusion.rb', line 206

def feedback_all_available_characters # Feedback all registered characters.
  e registered_names?.join(', ')
  e N+YELLOW+registered_names?.size.to_s+GREEN+' registered entries.'
end

#feedback_unique_charactersObject

#

feedback_unique_characters

#


221
222
223
224
# File 'lib/games_and_rpg_paradise/lpc/geas/character_exclusion.rb', line 221

def feedback_unique_characters
  e registered_names?.uniq.join(', ')
  e N+YELLOW+registered_names?.uniq.size.to_s+GREEN+' unique entries.'
end

#find_selectionsObject

#

find_selections

#


156
157
158
159
160
161
162
163
164
165
# File 'lib/games_and_rpg_paradise/lpc/geas/character_exclusion.rb', line 156

def find_selections
  selections = @dataset.select {|line| line.include? @name }
  selections.each {|line|
    splitted = line.split(',')
    splitted = splitted - [ @name ] # get rid of our own name
    @array_character_can_not_be_these_names << splitted
    @array_character_can_not_be_these_names = 
      @array_character_can_not_be_these_names.flatten.uniq
  }
end

#generate_completionObject

#

generate_completion

#


107
108
109
110
111
112
113
114
115
# File 'lib/games_and_rpg_paradise/lpc/geas/character_exclusion.rb', line 107

def generate_completion # generate the tab completion here
  this_file = 'completion_file_for_geas_mud_characters'
  _ = GenerateBashTabCompletion.new(false) # false for not running just yet.
  _.set_main_array @registered_names
  _.set_name_of_completion_file(this_file)
  _.run
  e 'Generating Completion next, will save into the file '
  e '  '+sfile( _.location )
end

#load_dataset(this_file = '/Depot/j/mud-05.10.2021/geas-05.10.2021/yaml/character_exclusion_data.yml') ⇒ Object

#

load_dataset

#


93
94
95
96
97
98
99
100
101
102
# File 'lib/games_and_rpg_paradise/lpc/geas/character_exclusion.rb', line 93

def load_dataset(
    # this_file = FILE_GEAS_CHARACTER_EXCLUSION_DATA
    this_file = '/Depot/j/mud-05.10.2021/geas-05.10.2021/yaml/character_exclusion_data.yml'
  )
  if File.exist? this_file
    @dataset = YAML.load_file(this_file)
  else
    e "No file exists at #{this_file}."
  end
end

#open_in_editorObject

#

open_in_editor

#


120
121
122
123
124
125
# File 'lib/games_and_rpg_paradise/lpc/geas/character_exclusion.rb', line 120

def open_in_editor
  e "Now opening #{THIS_FILE}"
  system "bluefish #{THIS_FILE}"
  e 'Also opening '+FILE_CHARACTER_DATASET
  system 'bluefish '+FILE_CHARACTER_DATASET
end

#registered_names?Boolean

#

feedback_unique_characters?

#

Returns:

  • (Boolean)


214
215
216
# File 'lib/games_and_rpg_paradise/lpc/geas/character_exclusion.rb', line 214

def registered_names?
  @registered_names.reject(&:empty?)
end

#report_possible_matchesObject

#

report_possible_matches

Use this method to suggest alternatives

#


179
180
181
182
183
184
185
# File 'lib/games_and_rpg_paradise/lpc/geas/character_exclusion.rb', line 179

def report_possible_matches
  matches = @registered_names.select {|entry|
    first_character = @name[0,1]
    entry =~ /^#{first_character}/
  }
  print '  '; e YELLOW+matches.join(', ')+rev
end

#report_resultsObject

#

report_results

#


249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/games_and_rpg_paradise/lpc/geas/character_exclusion.rb', line 249

def report_results
  e
  e main_colour?+'The character `'+teal(@name)+main_colour?+'` can '\
    'not be:'+rev
  sliced = @array_character_can_not_be_these_names.sort.each_slice(N_ROWS)
  cliner
  sliced.each {|array_with_four_members_containing_the_character_names|
    print sfancy(
        array_with_four_members_containing_the_character_names.map {|entry|
        ' - '+entry.ljust(16)
      }.join(' | ')
    )+N
  }; print main_colour?
  cliner
  e
end

#resetObject

#

reset

#


64
65
66
67
68
69
70
71
# File 'lib/games_and_rpg_paradise/lpc/geas/character_exclusion.rb', line 64

def reset
  # ======================================================================= #
  # === @array_character_can_not_be_these_names
  # ======================================================================= #
  @array_character_can_not_be_these_names = []
  load_dataset
  setup_registered_names
end

#runObject

#

run (run tag)

#


269
270
271
272
273
# File 'lib/games_and_rpg_paradise/lpc/geas/character_exclusion.rb', line 269

def run
  check_whether_character_is_registered_or_not
  find_selections
  report_results
end

#set_name(i = nil) ⇒ Object

#

set_name

#


130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/games_and_rpg_paradise/lpc/geas/character_exclusion.rb', line 130

def set_name(i = nil)
  i = DEFAULT_NAME if i.nil?
  case i # case tag
  when 'UNIQUE','unique'
    feedback_unique_characters
    exit
  when 'OPEN'
    open_in_editor
    exit
  when 'VIEW','ALL'
    feedback_all_available_characters
    exit
  when /^-?-?help/i
    show_help
    exit
  when 'COMPLETION','GENERATE','complete'
    generate_completion
    exit
  end
  i = i.capitalize # Keep it capitalized.
  @name = i
end

#setup_registered_namesObject

#

setup_registered_names

This method will find all unique names and store them in @registered_names.

#


79
80
81
82
83
84
85
86
87
88
# File 'lib/games_and_rpg_paradise/lpc/geas/character_exclusion.rb', line 79

def setup_registered_names
  @registered_names = []
  @dataset.each {|line|
    splitted = line.split(',')
    splitted.each {|inner_line|
      @registered_names << inner_line unless @registered_names.include? inner_line
    }
  }
  @registered_names = @registered_names.sort # keep them well sorted.
end

#show_helpObject

#

show_help (help tag)

#


229
230
231
232
233
234
235
236
237
# File 'lib/games_and_rpg_paradise/lpc/geas/character_exclusion.rb', line 229

def show_help
  e "Currently the following options are supported:#{N}#{N}"
  e
  e '  - '+YEL+'OPEN       '+GREEN+'# generate the completion'
  e '  - '+YEL+'COMPLETION '+GREEN+'# generate the completion'
  e '  - '+YEL+'GENERATE   '+GREEN+'# alias to the above ^^^'
  e '  - '+YEL+'VIEW       '+GREEN+'# view all registered names'+N+N
  e
end

#teal(i) ⇒ Object

#

teal

#


170
171
172
# File 'lib/games_and_rpg_paradise/lpc/geas/character_exclusion.rb', line 170

def teal(i)
  Colours.teal(i)
end