Class: Roebe::Slogans
- Inherits:
-
Base
show all
- Defined in:
- lib/roebe/classes/slogans.rb
Overview
Constant Summary
collapse
- N =
"\n"
- SLOGANS_FILE =
"#{HOME_DIRECTORY_OF_USER_X}DATA/science/yaml/"\
"slogans.yml"
- THIS_FILE_HERE =
__FILE__
- CD_ALIASES =
Rcfiles.file_cd_aliases?
- GREEN =
Colours::GREEN
- GREY =
Colours::GREY
Constants inherited
from Base
Base::COLOURS, Base::HOME_DIRECTORY_OF_USER_X, Base::NAMESPACE
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#actions, #append_this_onto_that_file, #append_what_into, #be_silent, #be_verbose?, #beautiful_url, #burlywood, #call_next, #chdir, #cheerful_guy, #cliner, #complex_esystem, #convert_global_env, #copy_directory, #copy_file, #cornflowerblue, #create_directory, #crimson, #current_month?, #current_time?, #current_year?, #cyan, #darkcyan, #darkgreen, #darkkhaki, #darkslateblue, #deeppink, #delete_symlink, #do_not_use_the_base_colours, #do_use_the_base_colours, #e, #ecomment, #editor_to_use?, #efancy, #eimp, #emphasis, #ensure_main_encoding, #ensure_utf_encoding, #eparse, #erev, #esteelblue, #etomato, #ewarn, #exit_program, #firebrick, #get_current_day, #get_current_month, #get_files_and_directories, #get_files_from, #get_german_name_for_this_weekday, #gold, #green, #grey, #hh_mm_ss, #hh_mm_ss_day_month_year, #home_dir?, #home_directory_of_user_x?, #infer_the_namespace, #internal_hash?, #is_a_directory?, #is_a_file?, #is_a_jpg_file?, #is_an_image_file?, #is_archive?, #is_audio_file?, #is_in_studium_dir?, #is_multimedia_file?, #is_on_roebe?, #is_on_windows?, #is_studium_available?, #is_symlink?, #is_this_a_ruby_file?, #is_video_file?, #iso_encoding?, #le, #left_colour, #lightblue, #lightgreen, #lightseagreen, #lightsteelblue, #lime, #limegreen, #localhost_to_data, #log_directory?, #main_encoding?, #mediumorchid, #mediumpurple, #mediumseagreen, #mediumslateblue, #mediumspringgreen, #mediumturquoise, #mkdir_p, #mv, #n_days_in_this_month, #n_pages_in_this_pdf_file?, #namespace?, #no_file_exists_at, #ogrey, #olive, #olivedrab, #open_in_browser, #opne, #opnesystem, #opnn, #orange, #orchid, #orev, #palegoldenrod, #palevioletred, #pink, #powderblue, #programs_dir?, #project_base_dir?, #random_html_colour, #rds, #read_file_in_iso_encoding, #read_file_via_the_default_encoding, #read_lines_via_iso_encoding, #readlines_with_main_encoding, #red, #register_sigint, #remove, #remove_directory, #remove_file, #rename_kde_konsole_tab, #replace_localhost_with_data, #report_pwd, #require_rescue, #reset_the_internal_hash, #return_all_directories_from_this_directory, #return_all_files_from_this_directory, #return_current_directory, #return_dd_mm_yyyy, #return_file_or_directory_of, #return_files_from_pwd, #return_last_part_of_the_current_directory, #return_utc, #rev, #right_arrow?, #right_colour, #roebe_log_directory?, #rosybrown, #royalblue, #ruby_base_directory?, #run_in_background, #run_rcfiles_then_run_ata_via_qdbus, #sandybrown, #sdir, #seagreen, #set_be_verbose, #set_xorg_buffer, #sfancy, #sfile, #show_help, #silent_redirection?, #simp, #simple_esystem, #skyblue, #slateblue, #slategray, #springgreen, #steelblue, #string_italic, #swarn, #symlink, #teal, #temp_dir?, #to_camelcase, #to_counted_hash, #tomato, #touch, #try_to_require_the_beautiful_url_gem, #try_to_require_the_html_template, #try_to_require_the_open_gem, #try_to_require_the_program_information_gem, #try_to_require_the_xorg_buffer, #use_colours?, #verbose_truth, #weekday?, #word_wrap, #write_what_into, #yellow
#append_onto_the_commandline_arguments, #clear_commandline_arguments, #commandline_arguments?, #commandline_arguments_as_string?, #commandline_arguments_without_leading_hyphens?, #first_argument?, #first_argument_without_leading_hyphens?, #has_an_argument_been_passed?, #remove_hyphened_arguments_from_the_commandline_arguments, #return_commandline_arguments_with_leading_hyphens, #second_argument?
Constructor Details
#initialize(i = nil, run_already = true) ⇒ Slogans
52
53
54
55
56
57
58
59
|
# File 'lib/roebe/classes/slogans.rb', line 52
def initialize(
i = nil,
run_already = true
)
reset
set_topic(i)
run if run_already
end
|
Instance Attribute Details
Returns the value of attribute slogans.
47
48
49
|
# File 'lib/roebe/classes/slogans.rb', line 47
def slogans
@slogans
end
|
Class Method Details
.show_slogans(this_topic = new(nil, false).topic) ⇒ Object
#
Roebe::Slogans.show_slogans
#
256
257
258
259
260
261
262
263
264
265
266
|
# File 'lib/roebe/classes/slogans.rb', line 256
def self.show_slogans(
this_topic = new(nil, false).topic
)
this_topic = this_topic.to_s
slogans = new(nil, false).slogans
if slogans.has_key? this_topic
return slogans[this_topic]
else
e 'Could not find Topic "'+sfancy(this_topic.to_s)+'".'
end
end
|
Instance Method Details
#determine_answer(this_answer = @slogans[@topic]) ⇒ Object
210
211
212
213
214
215
216
217
218
219
220
221
222
223
|
# File 'lib/roebe/classes/slogans.rb', line 210
def determine_answer(this_answer = @slogans[@topic])
_ = this_answer
if _
answer = _.sample
unless answer.end_with? '.'
case answer[-1,1]
when '!','?'
else
answer << '.'
end
end
@answer = answer
end
end
|
#determine_available_topics ⇒ Object
#
determine_available_topics
#
98
99
100
|
# File 'lib/roebe/classes/slogans.rb', line 98
def determine_available_topics
@available_topics = @slogans.keys
end
|
#fetch_random_topic ⇒ Object
194
195
196
|
# File 'lib/roebe/classes/slogans.rb', line 194
def fetch_random_topic
return @available_topics.sample
end
|
#load_available_slogans ⇒ Object
Also known as:
load_slogans, load_dataset
#
load_available_slogans
#
84
85
86
87
88
89
90
91
92
|
# File 'lib/roebe/classes/slogans.rb', line 84
def load_available_slogans
_ = SLOGANS_FILE
if File.exist? _
@slogans = YAML.load_file(_)
else
ewarn 'Slogans file `'+sfile(_)+'` does not exist, exiting now.'
exit
end
end
|
#load_slogans_and_determine_available_topics ⇒ Object
#
load_slogans_and_determine_available_topics
#
76
77
78
79
|
# File 'lib/roebe/classes/slogans.rb', line 76
def load_slogans_and_determine_available_topics
load_available_slogans
determine_available_topics
end
|
#open_in_editor(i) ⇒ Object
105
106
107
108
109
110
111
112
113
|
# File 'lib/roebe/classes/slogans.rb', line 105
def open_in_editor(i)
case i
when :slogans
i = SLOGANS_FILE
when :this_file_here
i = THIS_FILE_HERE
end
esystem 'bluefish '+i, :do_colourize_the_result
end
|
64
65
66
67
68
69
70
71
|
# File 'lib/roebe/classes/slogans.rb', line 64
def reset
super()
@answer = nil
load_slogans_and_determine_available_topics
end
|
#
run (run tag, main logic)
#
271
272
273
274
275
|
# File 'lib/roebe/classes/slogans.rb', line 271
def run
determine_topic unless @topic
determine_answer
show_slogan
end
|
#set_topic(i = @available_topics.sample) ⇒ Object
Also known as:
determine_topic
118
119
120
121
122
123
124
125
126
127
128
129
130
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
# File 'lib/roebe/classes/slogans.rb', line 118
def set_topic(i = @available_topics.sample)
if i.is_a? Array
_ = i.shift
set_commandline_arguments i
i = _
end
i = :random if i.nil?
case i
when :random
i = fetch_random_topic
end
if @commandline_arguments
case _
when 'default', nil
when 'OPEN_ALL','OPENALL'
open_in_editor :slogans
open_in_editor :this_file_here
exit
when /^PR/
target = File.readlines(CD_ALIASES)
target.reject! {|entry| entry !~ /^pwdstud:/ }
slogans_file = target[0].chomp.gsub(/pwdstud: cd /,'')+'/SLOGANS'
_ = File.read(slogans_file).split('- ').reject {|entry| entry.empty? }
_.map! {|entry| entry.delete("\n").gsub(/ /,' ') }
_ = _.sample
show_answer(_)
exit
when 'OPEN','EDIT'
open_in_editor :slogans
exit
when 'OPEN_RB'
open_in_editor :this_file_here
exit
when 'chromo','CHROMO'
i = 'chromosomenbiologie'
when 'mikrobio','witte'
i = 'mikrobiologie'
when 'genex','genexp'
i = 'genexpression'
when 'bio'
i = 'biologie'
when 'evo'
i = 'evolution'
when 'signal'
i = 'signaltransduktion'
when 'epi'
i = 'epigenetik'
when 'biochemie','bem'
i = 'biochem'
when 'chem'
i = 'chemistry'
when 'amg'
i = 'genetik'
end
if @available_topics.include? @commandline_arguments.first
i = @commandline_arguments.first
end
end
@topic = i
end
|
#show_answer(i = @answer) ⇒ Object
242
243
244
|
# File 'lib/roebe/classes/slogans.rb', line 242
def show_answer(i = @answer)
e ' '+GREEN+i.to_s+N+N
end
|
#show_slogan ⇒ Object
228
229
230
231
232
233
234
235
236
237
|
# File 'lib/roebe/classes/slogans.rb', line 228
def show_slogan
show_topic
second_argument = @commandline_arguments[0]
case second_argument
when 'ALL'
@slogans[@topic].each {|answer| show_answer(answer) }
else
show_answer
end
end
|
#show_topic ⇒ Object
#
show_topic
Here we will show the proper title, then a newline.
#
203
204
205
|
# File 'lib/roebe/classes/slogans.rb', line 203
def show_topic
e N+GREY+@topic.capitalize+':'+rev+N+N
end
|
#topic? ⇒ Boolean
Also known as:
topic
249
250
251
|
# File 'lib/roebe/classes/slogans.rb', line 249
def topic?
@topic
end
|