Class: GamesAndRpgParadise::Lpc::Geas::WhoListAnalyzer
- Inherits:
-
Lpc::Base
- Object
- Lpc::Base
- GamesAndRpgParadise::Lpc::Geas::WhoListAnalyzer
show all
- Defined in:
- lib/games_and_rpg_paradise/lpc/geas/who_list_analyzer.rb
Overview
GamesAndRpgParadise::Lpc::Geas::WhoListAnalyzer
Constant Summary
collapse
- SHOW_ONLY_GUILDED_CHARACTERS =
#
SHOW_ONLY_GUILDED_CHARACTERS
If this constant is set to true then we will show only guilded characters. In other words, we will not show unguilded characters.
#
true
- EXIT_ON_UNREGISTERED_CHARACTER =
#
EXIT_ON_UNREGISTERED_CHARACTER
If true then we will exit if we found an undiscovered char.
#
false
Class Method Summary
collapse
-
.[](i = ARGV) ⇒ Object
# === GamesAndRpgParadise::Lpc::Geas::WhoListAnalyzer[] ========================================================================= #.
Instance Method Summary
collapse
Constructor Details
#initialize(use_this_who_list = ARGV, run_already = true) ⇒ WhoListAnalyzer
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/games_and_rpg_paradise/lpc/geas/who_list_analyzer.rb', line 49
def initialize(
use_this_who_list = ARGV,
run_already = true
)
reset
set_use_this_who_list(
use_this_who_list
)
run if run_already
end
|
Class Method Details
.[](i = ARGV) ⇒ Object
#
GamesAndRpgParadise::Lpc::Geas::WhoListAnalyzer[]
#
307
308
309
|
# File 'lib/games_and_rpg_paradise/lpc/geas/who_list_analyzer.rb', line 307
def self.[](i = ARGV)
new(i)
end
|
Instance Method Details
#check_whether_these_characters_exist(array) ⇒ Object
#
check_whether_these_characters_exist
We try to find unregistered characters via this method here.
#
190
191
192
193
194
195
196
|
# File 'lib/games_and_rpg_paradise/lpc/geas/who_list_analyzer.rb', line 190
def check_whether_these_characters_exist(array)
array.each {|character|
unless dataset_contains_this_character? character
report_this_unregistered_character(character)
end
}
end
|
#dataset_contains_this_character?(i) ⇒ Boolean
Also known as:
is_this_character_in_a_guild?
#
dataset_contains_this_character?
#
201
202
203
|
# File 'lib/games_and_rpg_paradise/lpc/geas/who_list_analyzer.rb', line 201
def dataset_contains_this_character?(i)
@characters_in_guilds.include? i
end
|
#do_report ⇒ Object
Also known as:
process_dataset
#
do_report
Report to the user finally.
#
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
|
# File 'lib/games_and_rpg_paradise/lpc/geas/who_list_analyzer.rb', line 232
def do_report
who_list?.each {|array| n_characters = array.size
opn; e 'The dataset includes these '+sfancy(n_characters)+
' characters (stats):'
hash_how_many_individuals = {}
hash_how_many_individuals.default = 0
array.each {|inner_member|
this_guild = @characters_in_guilds[inner_member]
hash_how_many_individuals[this_guild] += 1
}
array = hash_how_many_individuals.sort_by {|key, value| value }
hash_how_many_individuals = array.reverse.to_h report_hash_showing_how_many_characters_were_available(
hash_how_many_individuals, n_characters
)
cliner
}
end
|
#report_hash_showing_how_many_characters_were_available(hash, total_amount) ⇒ Object
#
report_hash_showing_how_many_characters_were_available
#
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
|
# File 'lib/games_and_rpg_paradise/lpc/geas/who_list_analyzer.rb', line 281
def report_hash_showing_how_many_characters_were_available(
hash, total_amount
)
hash.each_pair {|key, value|
key = key.to_s+':'
if key.delete(':') == 'Unaffiliated'
next
end if SHOW_ONLY_GUILDED_CHARACTERS
e ' '+sfancy(key.ljust(22))+value.to_s+
report_stats(
hash[key.delete(':')],
total_amount
) }
end
|
#report_stats(key, total_amount = who?.size) ⇒ Object
#
report_stats
We report how much this is in % percentage.
#
266
267
268
269
270
271
272
273
274
275
276
|
# File 'lib/games_and_rpg_paradise/lpc/geas/who_list_analyzer.rb', line 266
def report_stats(key, total_amount = who?.size)
if Object.const_defined? :Percentage
value = Percentage[key.to_f, total_amount.to_f].string_value?
if value.size < 5 and value.split('.').last.size < 2
value = value.ljust(5, '0')
end
' ('+value.rjust(5, ' ')+'%)'
else
''
end
end
|
#report_this_unregistered_character(character) ⇒ Object
#
report_this_unregistered_character
#
208
209
210
211
212
213
214
215
216
|
# File 'lib/games_and_rpg_paradise/lpc/geas/who_list_analyzer.rb', line 208
def report_this_unregistered_character(character)
ewarn 'The character `'+character.to_s+'` is not registered '\
'to be in any guild/organization.'
if EXIT_ON_UNREGISTERED_CHARACTER
e 'Exiting now as specified by the constant '\
'EXIT_ON_UNREGISTERED_CHARACTER'
exit
end
end
|
#reset ⇒ Object
116
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/games_and_rpg_paradise/lpc/geas/who_list_analyzer.rb', line 116
def reset
super()
@who_list = nil if File.exist? CHARACTERS_IN_GUILDS
@characters_in_guilds = YAML.load_file(CHARACTERS_IN_GUILDS)
sanitize_characters_in_guilds
else
e 'No file could be found at '+sfile(CHARACTERS_IN_GUILDS)
@characters_in_guilds = {}
end
end
|
#return_full_yaml_file(i = yaml_file_with_all_who_snapshots?)
) ⇒ Object
#
return_full_yaml_file
#
70
71
72
73
74
|
# File 'lib/games_and_rpg_paradise/lpc/geas/who_list_analyzer.rb', line 70
def return_full_yaml_file(i = yaml_file_with_all_who_snapshots?)
File.readlines(i).select {|entry|
entry.start_with? '- '
}
end
|
#run ⇒ Object
300
301
302
|
# File 'lib/games_and_rpg_paradise/lpc/geas/who_list_analyzer.rb', line 300
def run
do_report
end
|
#sanitize_characters_in_guilds ⇒ Object
#
sanitize_characters_in_guilds
We need to expand the shortcuts here, to the corresponding guild at hand (for guilded characters).
#
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/games_and_rpg_paradise/lpc/geas/who_list_analyzer.rb', line 82
def sanitize_characters_in_guilds
_ = {}
@characters_in_guilds.each {|key, value|
case value
when 'Una'
value = 'Unaffiliated'
when 'Taniel'
value = 'Cleric of Taniel'
when 'Satho'
value = 'Cleric of Sathonys'
when 'Asral'
value = 'Cleric of Asral'
when 'Shao'
value = 'Shaolin'
end
_[key] = value
}
@characters_in_guilds = _ end
|
#sanitize_who_list ⇒ Object
#
sanitize_who_list
We need to sanitize the who list here.
#
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
# File 'lib/games_and_rpg_paradise/lpc/geas/who_list_analyzer.rb', line 165
def sanitize_who_list
wholist.map! {|entry| if entry.is_a? String and entry.include?(',')
entry = entry.split(',').map {|entry| entry.delete('-') }.map(&:strip)
end
entry.map! {|inner_entry| inner_entry = inner_entry.to_s.dup if inner_entry.frozen?
inner_entry.delete!('-') if inner_entry.include? '-'
inner_entry.delete!('"') if inner_entry.include? '"'
inner_entry.delete(N) if inner_entry.include? N
inner_entry.strip!
if inner_entry.include? ','
inner_entry = inner_entry.split(',').sort
check_whether_these_characters_exist(inner_entry)
end
}
entry.flatten(1)
}
end
|
#set_use_this_who_list(i = nil) ⇒ Object
Also known as:
who_list=
#
set_use_this_who_list
#
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
# File 'lib/games_and_rpg_paradise/lpc/geas/who_list_analyzer.rb', line 131
def set_use_this_who_list(i = nil)
if i.nil?
i = return_full_yaml_file
end
if i.is_a? Array
if i.empty?
i = return_full_yaml_file
end
case i.first when /^-?-?help/i
show_help; exit
else
if File.exist? i.first i = File.readlines(i.first)
end
end
end
if i.is_a? String
if File.exist? i
i = File.readlines(i)
end
i = [i] end
i = [i] unless i.is_a? Array i.flatten!
@who_list = i
sanitize_who_list
end
|
#show_help ⇒ Object
105
106
107
108
109
110
111
|
# File 'lib/games_and_rpg_paradise/lpc/geas/who_list_analyzer.rb', line 105
def show_help
e
opn; e 'These options are currently available:'
e
e ' gwho EXISTING_FILE # We will read in this file.'
e
end
|
#who_list? ⇒ Boolean
Also known as:
wholist, wholist?, who?
221
222
223
|
# File 'lib/games_and_rpg_paradise/lpc/geas/who_list_analyzer.rb', line 221
def who_list?
@who_list
end
|
#yaml_file_with_all_who_snapshots? ⇒ Boolean
63
64
65
|
# File 'lib/games_and_rpg_paradise/lpc/geas/who_list_analyzer.rb', line 63
def yaml_file_with_all_who_snapshots?
CHARACTER_EXCLUSION_DATA end
|