Class: Roebe::At
Overview
Constant Summary
collapse
- A_FULL_DAY =
'24:00:00'
- DEFAULT_WAKEUP_TIME =
'08:00:00'
Constants inherited
from Base
Base::COLOURS, Base::HOME_DIRECTORY_OF_USER_X, Base::N, Base::NAMESPACE
Class Method Summary
collapse
-
.[](i = nil) ⇒ Object
# === Roebe::At[] ========================================================================= #.
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_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?, #set_commandline_arguments
Constructor Details
#initialize(start_at_this_time = nil, run_already = true) ⇒ At
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/roebe/classes/at.rb', line 48
def initialize(
start_at_this_time = nil,
run_already = true
)
register_sigint
reset
set_start_wecker_at_this_time(
start_at_this_time
)
run if run_already
end
|
Class Method Details
.[](i = nil) ⇒ Object
326
327
328
|
# File 'lib/roebe/classes/at.rb', line 326
def self.[](i = nil)
new(i)
end
|
Instance Method Details
#calculate_the_difference ⇒ Object
#
calculate_the_difference
For this method to work, we need to convert stuff into seconds.
The input may be:
at 23:00:00
at 07:00:00
The output of this method will be in n seconds.
#
138
139
140
141
142
143
144
145
146
147
148
|
# File 'lib/roebe/classes/at.rb', line 138
def calculate_the_difference
if today?
@n_seconds = duration(wake_up_when?) - duration(current_time?)
else current_time = duration(full_day?) - duration(current_time?)
end_time = duration(wake_up_when?)
@n_seconds = end_time + current_time
end
end
|
#consider_resetting_the_studium_exams_per_day_answered_file ⇒ Object
#
consider_resetting_the_studium_exams_per_day_answered_file
This method is only relevant on my home system, so the if-clause checks whether I am on my home system.
#
234
235
236
237
238
239
240
241
242
|
# File 'lib/roebe/classes/at.rb', line 234
def consider_resetting_the_studium_exams_per_day_answered_file
if is_on_roebe?
require 'studium/logging/store_last_question_asked_into_file.rb'
Studium::Log::StoreLastQuestionAskedIntoFile.reset_file
end
end
|
#current_time? ⇒ Boolean
160
161
162
|
# File 'lib/roebe/classes/at.rb', line 160
def current_time?
@current_time
end
|
#duration(i) ⇒ Object
#
duration
duration ‘01:00:00’ would return 3600.
#
223
224
225
226
|
# File 'lib/roebe/classes/at.rb', line 223
def duration(i)
h,m,s = i.split(/:/).map(&:to_i)
h * 3600 + m * 60 + s
end
|
#full_day? ⇒ Boolean
77
78
79
|
# File 'lib/roebe/classes/at.rb', line 77
def full_day?
A_FULL_DAY
end
|
#kill_all_instances_of_mpv_or_mplayer_found_here(i) ⇒ Object
#
kill_all_instances_of_mpv_or_mplayer_found_here
This method was added in October 2022, largely because on Linux we sometimes can only run one instance of mpv/mplayer, for some odd reason. Rather than investigate why that is so I decided to solve this indirectly by adding this method here.
#
299
300
301
302
303
304
305
306
307
308
309
310
311
|
# File 'lib/roebe/classes/at.rb', line 299
def kill_all_instances_of_mpv_or_mplayer_found_here(i)
if i
[i].flatten.compact.each {|line|
process_id = line.split(' ').map(&:strip)[1]
process_id = process_id.to_i
Process.kill('QUIT', process_id) unless process_id < 3 }
end
end
|
#n_seconds_in_a_day? ⇒ Boolean
110
111
112
|
# File 'lib/roebe/classes/at.rb', line 110
def n_seconds_in_a_day?
duration(full_day?)
end
|
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/roebe/classes/at.rb', line 63
def reset
super()
infer_the_namespace
@current_time = ::Time.now.strftime('%H:%M:%S') end
|
#reset_konsole_tab ⇒ Object
153
154
155
|
# File 'lib/roebe/classes/at.rb', line 153
def reset_konsole_tab
try_to_rename_the_konsole_tab '_'
end
|
316
317
318
319
320
321
|
# File 'lib/roebe/classes/at.rb', line 316
def run
calculate_the_difference
try_to_rename_the_konsole_tab
consider_resetting_the_studium_exams_per_day_answered_file
start_the_main_loop
end
|
#seconds_to_minutes(i) ⇒ Object
175
176
177
178
179
180
181
182
183
184
185
186
187
|
# File 'lib/roebe/classes/at.rb', line 175
def seconds_to_minutes(i)
n_minutes_calculated = (i.to_f / 60.0).floor
result = rev+'(+'+steelblue(n_minutes_calculated.to_s)+
rev+' minutes'
result << rev+', thus about '+
steelblue((n_minutes_calculated.to_f / 60.0).floor.to_s)+
rev+' hours of sleep'
result << ')'
return result
end
|
#set_start_wecker_at_this_time(i = nil) ⇒ Object
#
set_start_wecker_at_this_time
#
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/roebe/classes/at.rb', line 84
def set_start_wecker_at_this_time(i = nil)
if i.nil? or (i.is_a?(Array) && i.empty?)
e 'Please provide an argument, such as:'
e ' at 08:00:00'
exit
end
i = i.first if i.is_a? Array
i = i.to_s.dup
case i when 'EIGHT'
i = '8:00:00'
when 'NINE'
i = '9:00:00'
when 'TEN'
i = '10:00:00'
end
i.tr!('.',':') if i.include? '.'
if i.count(':') == 1 i << ':00'
end
@start_wecker_at_this_time = i
end
|
#start_the_main_loop ⇒ Object
247
248
249
|
# File 'lib/roebe/classes/at.rb', line 247
def start_the_main_loop
wait_for_n_seconds(@n_seconds)
end
|
#start_when? ⇒ Boolean
Also known as:
wake_up_when?, target?
167
168
169
|
# File 'lib/roebe/classes/at.rb', line 167
def start_when?
@start_wecker_at_this_time
end
|
277
278
279
280
281
282
283
284
285
286
287
288
289
|
# File 'lib/roebe/classes/at.rb', line 277
def stop_all_other_multimedia_instances
results = `ps aux`
if results
results = results.split(N)
selection = results.select {|entry|
entry.include?(' mpv ') or
entry.include?(' mplayer ')
}
unless selection.empty?
kill_all_instances_of_mpv_or_mplayer_found_here(selection)
end
end
end
|
#today? ⇒ Boolean
117
118
119
120
121
122
123
124
|
# File 'lib/roebe/classes/at.rb', line 117
def today?
if duration(target?) > duration(current_time?)
result = true
else
result = false
end
result
end
|
#try_to_log_into_a_log_file ⇒ Object
#
try_to_log_into_a_log_file
#
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
# File 'lib/roebe/classes/at.rb', line 203
def try_to_log_into_a_log_file
_ = temp_dir?
if !File.directory?(_)
if File.directory?(temp_dir?)
_ = temp_dir?
end
end
if File.directory? _
what = 'Started the ascii countdown at: '+::Time.now.to_s
into = "#{_}at_logfile.log"
opne "Storing into the logfile at `#{sfile(into)}`."
write_what_into(what, into)
end
end
|
#try_to_rename_the_konsole_tab(use_this_title = @start_wecker_at_this_time.to_s) ⇒ Object
#
try_to_rename_the_konsole_tab
#
192
193
194
195
196
197
198
|
# File 'lib/roebe/classes/at.rb', line 192
def try_to_rename_the_konsole_tab(
use_this_title = @start_wecker_at_this_time.to_s
)
if Object.const_defined? :Roebe
Roebe::KdeKonsole.new(use_this_title)
end
end
|
#wait_for_n_seconds(i) ⇒ Object
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
|
# File 'lib/roebe/classes/at.rb', line 254
def wait_for_n_seconds(i)
begin
require 'ascii_countdown'
rescue LoadError => error
pp error
e 'An error happened.'
end
e "#{rev}Now waiting for `#{sfancy(i.to_s)}#{rev}` "\
"seconds #{seconds_to_minutes(i)}#{rev}."
e "#{rev}We will wake up at #{royalblue(@start_wecker_at_this_time)}#{rev}."
::AsciiCountdown.new(i) try_to_log_into_a_log_file reset_konsole_tab stop_all_other_multimedia_instances
MultimediaParadise.action(:AudioPlayer, :play_all_songs)
end
|