Class: Roebe::GeneralOverviewer

Inherits:
Base show all
Defined in:
lib/roebe/classes/general_overviewer.rb

Overview

Roebe::GeneralOverviewer

Constant Summary

Constants inherited from Base

Base::COLOURS, Base::HOME_DIRECTORY_OF_USER_X, Base::N, Base::NAMESPACE

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, #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

Methods included from Base::CommandlineArguments

#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(i = nil, run_already = true) ⇒ GeneralOverviewer

#

initialize

#


29
30
31
32
33
34
35
36
# File 'lib/roebe/classes/general_overviewer.rb', line 29

def initialize(
    i           = nil,
    run_already = true
  )
  reset
  set_input(i)
  run if run_already
end

Class Method Details

.[](i = '') ⇒ Object

#

Roebe::GeneralOverviewer[]

#


261
262
263
# File 'lib/roebe/classes/general_overviewer.rb', line 261

def self.[](i = '')
  new(i)
end

Instance Method Details

#check_for_local_holidaysObject

#

check_for_local_holidays

This method has been added on 03.06.2021 specifically so I don’t forget that today may be a holiday (where shops then are closed).

#


226
227
228
229
# File 'lib/roebe/classes/general_overviewer.rb', line 226

def check_for_local_holidays
  require 'roebe/classes/holiday.rb'
  Roebe::Holiday.new {{ prepend_this_string: '  Is today a holiday:               ' }}
end

#display_current_timeObject

#

display_current_time

This method will display the current “Uhrzeit”, aka current time.

#


206
207
208
209
# File 'lib/roebe/classes/general_overviewer.rb', line 206

def display_current_time
  e rev+'  Uhrzeit:'.ljust(@ljust_value)+
    sfancy(hh_mm_ss(::Time.now).rjust(@rjust_value))
end

#display_current_time_via_hwclockObject

#

display_current_time_via_hwclock

#


214
215
216
217
218
# File 'lib/roebe/classes/general_overviewer.rb', line 214

def display_current_time_via_hwclock
  result = `hwclock`.scan(/\d{2}:\d{2}:\d{2}/).first.to_s.strip
  e rev+'  Uhrzeit (hwclock):'.ljust(@ljust_value)+
    sfancy(result.rjust(@rjust_value))
end

#input?Boolean

#

input?

#

Returns:

  • (Boolean)


67
68
69
# File 'lib/roebe/classes/general_overviewer.rb', line 67

def input?
  @input
end
#

menu (menu tag)

#


74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/roebe/classes/general_overviewer.rb', line 74

def menu(
    i = @input
  )
  if i.is_a? Array
    i.each {|entry| menu(entry) }
  else
    case i
    # ===================================================================== #
    # === date  --no-internet
    #
    # This entry point can be used specifically when access to the www
    # is presently unavailable.
    # ===================================================================== #
    when /^-?-?no(-|_)?internet$/,
         /^-?-?no(-|_)?date$/,
         /^-?-?no(-|_)?time$/,
         /^-?-?no(-|_)?www$/,
         /^-?-?no(-|_)?web$/
      @check_for_the_local_weather = false
    # ===================================================================== #
    # === date --help
    # ===================================================================== #
    when /help/
      show_help
      exit
    end
  end
end

#obtain_timeObject

#

obtain_time

#


176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/roebe/classes/general_overviewer.rb', line 176

def obtain_time
  ENV['TZ'] = ''
  # ======================================================================= #
  # === @today
  # ======================================================================= #
  @today        = today?
  # ======================================================================= #
  # === @current_time
  # ======================================================================= #
  # @current_time = current_time?
  cmd = 'date +"%T"'
  @current_time = `#{cmd}`.strip
  obtain_weekday # This method will set the @weekday variable.
end

#obtain_weatherObject

#

obtain_weather

#


123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/roebe/classes/general_overviewer.rb', line 123

def obtain_weather
  if @check_for_the_local_weather
    begin
      require 'chemistry_paradise' unless Object.const_defined? :ChemistryParadise
    rescue LoadError; end
    begin
      @weather = ChemistryParadise.return_current_degrees
    rescue Exception => error
      pp error
      pp error.class
    end
  end
end

#obtain_weekdayObject

#

obtain_weekday

#


194
195
196
197
198
199
# File 'lib/roebe/classes/general_overviewer.rb', line 194

def obtain_weekday
  # ======================================================================= #
  # The method will change "Sat" into "Satuday and so forth:
  # ======================================================================= #
  @weekday = translate_english_weekday_into_german_weekday(weekday?)
end

#report_resultsObject Also known as: report

#

report_results

We will report in german for now.

#


236
237
238
239
240
241
242
243
244
# File 'lib/roebe/classes/general_overviewer.rb', line 236

def report_results
  e
  e rev+'  Datum:'.ljust(@ljust_value)+
    mediumpurple(@today.rjust(@rjust_value))
  display_current_time
  display_current_time_via_hwclock
  e rev+'  Wochentag:'.ljust(@ljust_value)+
    lightgreen(@weekday.rjust(@rjust_value))
end

#report_weatherObject

#

report_weather (weather tag)

This method will report the weather. The reason why this is separate from the other parts is because the determining the weather may take a little, whereas the other results can happen instantly.

#


144
145
146
147
148
149
150
# File 'lib/roebe/classes/general_overviewer.rb', line 144

def report_weather
  obtain_weather
  if @weather
    e rev+'  Aktuelle Temperatur in Wien: '.ljust(@ljust_value)+
      royalblue((@weather.to_s.+'°C').rjust(@rjust_value))
  end
end

#resetObject

#

reset (reset tag)

#


41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/roebe/classes/general_overviewer.rb', line 41

def reset
  super()
  # ======================================================================= #
  # === @weather
  # ======================================================================= #
  @weather = nil
  # ======================================================================= #
  # === @check_for_the_local_weather
  # ======================================================================= #
  @check_for_the_local_weather = true
  @ljust_value = 36
  @rjust_value = 10
end

#return_current_time_in_a_colourized_manner(optional_rjust_value = 40) ⇒ Object

#

return_current_time_in_a_colourized_manner

#


164
165
166
167
168
169
170
171
# File 'lib/roebe/classes/general_overviewer.rb', line 164

def return_current_time_in_a_colourized_manner(
    optional_rjust_value = 40
  )
  _ = @current_time.rjust(optional_rjust_value)
  splitted = _.split(':')
  splitted.map! {|entry| mediumspringgreen(entry) }
  return splitted.join(orange(':'))
end

#runObject

#

run (run tag)

#


249
250
251
252
253
254
255
256
# File 'lib/roebe/classes/general_overviewer.rb', line 249

def run
  menu
  obtain_time
  report_results
  report_weather
  check_for_local_holidays
  e
end

#set_input(i = '') ⇒ Object

#

set_input

#


58
59
60
61
62
# File 'lib/roebe/classes/general_overviewer.rb', line 58

def set_input(i = '')
  i = [i] unless i.is_a? Array
  i.compact!
  @input = i
end

#show_helpObject

#

show_help

To invoke this method, do:

date --show_help
#


111
112
113
114
115
116
117
118
# File 'lib/roebe/classes/general_overviewer.rb', line 111

def show_help
  e
  e 'The following options are available:'
  e
  e '  --no-internet # use this when you have no '\
    'working internet connection'
  e
end

#translate_english_weekday_into_german_weekday(i) ⇒ Object

#

translate_english_weekday_into_german_weekday

#


155
156
157
158
159
# File 'lib/roebe/classes/general_overviewer.rb', line 155

def translate_english_weekday_into_german_weekday(i)
  long_name   = Studium::HASH_SHORT_TO_LONG_WEEKDAYS[i.to_s]
  german_name = Studium::ENGLISH_TO_GERMAN_WEEKDAYS[long_name]
  return german_name
end