Class: Roebe::Calendar
- Inherits:
-
Base
show all
- Defined in:
- lib/roebe/classes/calendar.rb
Constant Summary
collapse
- TODAYS_DAY_AS_NUMBER =
#
TODAYS_DAY_AS_NUMBER
Keep track of today’s weekday.
#
::Time.now.strftime('%d')
- WEEKDAYS =
#
WEEKDAYS
Valid Weekdays. Sunday, Monday, Tuesday Wednesday etc..
#
%w(
S M Tu W Th F S
)
- ARRAY_ALL_MONTHS =
%w(
January February
March April
May June
July August
September October
November December
)
- START =
{
'at' => 2342032, 'cn' => Date::GREGORIAN, 'de' => 2342032, 'dk' => 2342032, 'es' => 2299161, 'fi' => 2361390, 'fr' => 2299227, 'gb' => 2361222, 'gr' => 2423868, 'hu' => 2301004, 'it' => 2299161, 'jp' => Date::GREGORIAN, 'no' => 2342032, 'pl' => 2299161, 'pt' => 2299161, 'ru' => 2421639, 'se' => 2361390, 'us' => 2361222, 'os' => Date::JULIAN, 'ns' => Date::GREGORIAN }
- DEFAULT_START =
#
DEFAULT_START
Denote your country here, if you want to.
#
'at'
Constants inherited
from Base
Base::COLOURS, Base::HOME_DIRECTORY_OF_USER_X, Base::N, Base::NAMESPACE
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?, #set_commandline_arguments
Constructor Details
#initialize(optional_arguments = ARGV) ⇒ Calendar
#
initialize
The arguments are presently not in use.
#
89
90
91
92
|
# File 'lib/roebe/classes/calendar.rb', line 89
def initialize(optional_arguments = ARGV)
reset
run
end
|
Instance Method Details
#addmon(year, m, n) ⇒ Object
268
269
270
271
|
# File 'lib/roebe/classes/calendar.rb', line 268
def addmon(year, m, n)
year, m = (y * 12 + (m - 1) + n).divmod(12)
return year, m + 1
end
|
#append_newline(i) ⇒ Object
#
append_newline
This method will simply append a newline to the Array in question, before converting it into a String.
#
252
253
254
|
# File 'lib/roebe/classes/calendar.rb', line 252
def append_newline(i)
i.map {|x| x + N}.join
end
|
#block(xs, n) ⇒ Object
242
243
244
|
# File 'lib/roebe/classes/calendar.rb', line 242
def block(xs, n)
stack(group(xs, n).map {|ys| trans(ys).map {|zs| zs.join(' ')}})
end
|
#colourize_in_red(i) ⇒ Object
208
209
210
|
# File 'lib/roebe/classes/calendar.rb', line 208
def colourize_in_red(i)
swarn(i)
end
|
#group(xs, n) ⇒ Object
215
216
217
218
219
|
# File 'lib/roebe/classes/calendar.rb', line 215
def group(xs, n)
(0..xs.size / n - 1).map {|i|
xs[i * n, n]
}
end
|
#monthly(year, month) ⇒ Object
259
260
261
262
263
|
# File 'lib/roebe/classes/calendar.rb', line 259
def monthly(year, month)
append_newline(
pict(year, month)
)
end
|
#opt_c(arg = DEFAULT_START) ⇒ Object
134
135
136
|
# File 'lib/roebe/classes/calendar.rb', line 134
def opt_c(arg = DEFAULT_START)
@start = START[arg]
end
|
#opt_j(flag = false) ⇒ Object
106
107
108
|
# File 'lib/roebe/classes/calendar.rb', line 106
def opt_j(flag = false)
@opt_j = flag
end
|
#opt_m(flag = false) ⇒ Object
113
114
115
|
# File 'lib/roebe/classes/calendar.rb', line 113
def opt_m(flag = false)
@opt_m = flag
end
|
#opt_t(flag = false) ⇒ Object
120
121
122
|
# File 'lib/roebe/classes/calendar.rb', line 120
def opt_t(flag = false)
@opt_t = flag
end
|
#opt_y(flag = false) ⇒ Object
127
128
129
|
# File 'lib/roebe/classes/calendar.rb', line 127
def opt_y(flag = false)
@opt_y = flag
end
|
#pict(year, month) ⇒ Object
#
pict (pict tag)
y is year, example 2006.
The second argument month denotes which month we have.
#
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
# File 'lib/roebe/classes/calendar.rb', line 158
def pict(year, month)
d = (1..31).detect {|inner_d|
Date.valid_date?(year, month, inner_d, @start)
}
fi = Date.new(year, month, d, @start)
fi -= (fi.jd - @k + 1) % 7
ve = (fi..fi + 6).map {|cu|
WEEKDAYS[cu.wday]
}
ve += (fi..fi + 41).map {|cu|
if cu.mon == month
cu.send(@da)
end.to_s
}
ve.map! {|e|
result = e.rjust(@dw)
if @use_colours
if result.strip == TODAYS_DAY_AS_NUMBER
result = colourize_in_red(result) end
end
result
}
gr = group(ve, 7) gr = trans(gr) if @opt_t
ta = gr.map {|x| x.join(' ')}
month_and_year = ARRAY_ALL_MONTHS[month - 1] month_and_year = month_and_year+ ' '+year.to_s unless @opt_y
month_and_year = month_and_year.center(@mw)+N
ta.unshift(month_and_year)
end
|
#print(year = Date.today.year, month = Date.today.month) ⇒ Object
#
print (print tag)
Modified print-method.
#
290
291
292
293
294
295
296
297
|
# File 'lib/roebe/classes/calendar.rb', line 290
def print(year = Date.today.year, month = Date.today.month)
set_params
if @opt_y
yearly(year)
else
monthly(year, month)
end
end
|
97
98
99
100
101
|
# File 'lib/roebe/classes/calendar.rb', line 97
def reset
super()
@use_colours = true
end
|
302
303
304
305
|
# File 'lib/roebe/classes/calendar.rb', line 302
def run
e opt_j; opt_m; opt_t; opt_y; opt_c end
|
#set_params ⇒ Object
141
142
143
144
145
146
147
148
149
|
# File 'lib/roebe/classes/calendar.rb', line 141
def set_params
@dw = if @opt_j then 3 else 2 end
@mw = (@dw + 1) * 7 - 1
@mn = if @opt_j then 2 else 3 end
@tw = (@mw + 2) * @mn - 2
@k = if @opt_m then 1 else 0 end
@da = :mday
@da = :yday if @opt_j
end
|
#stack(xs) ⇒ Object
231
232
233
234
235
236
237
|
# File 'lib/roebe/classes/calendar.rb', line 231
def stack(xs)
if xs.empty?
[]
else
xs[0] + stack(xs[1..-1])
end
end
|
#trans(xs) ⇒ Object
224
225
226
|
# File 'lib/roebe/classes/calendar.rb', line 224
def trans(xs)
(0..xs[0].size - 1).map {|i| xs.map {|x| x[i]}}
end
|
#yearly(y) ⇒ Object
#
yearly
This method will display the month and the year in question.
#
278
279
280
281
282
283
|
# File 'lib/roebe/classes/calendar.rb', line 278
def yearly(y)
y.to_s.center(@tw)+N+N+
append_newline( block((0..11).map {|n|
pict(*addmon(y, 1, n))
}, @mn)) + N
end
|