Class: Roebe::Books
- Inherits:
-
Base
show all
- Defined in:
- lib/roebe/classes/books/menu.rb,
lib/roebe/classes/books/books.rb
Overview
Constant Summary
collapse
- TRY_TO_OPEN_PDF_FILES_IN_FULLSCREEN =
#
TRY_TO_OPEN_PDF_FILES_IN_FULLSCREEN
If true then the .pdf file will be opened in fullscreen.
#
false
- SHOW_HOW_MANY_PAGES_ARE_IN_THAT_PDF_FILE =
#
SHOW_HOW_MANY_PAGES_ARE_IN_THAT_PDF_FILE
If the following constant is set to true then this class will also report how many pages are in a given .pdf file at hand. This may take some time, so a constant was added to quickly be able to toggle the behaviour of this class.
#
true
Constants inherited
from Base
Roebe::Base::COLOURS, Roebe::Base::HOME_DIRECTORY_OF_USER_X, Roebe::Base::N, Roebe::Base::NAMESPACE
Instance Method Summary
collapse
-
#add_this_pdf_file_towards_that_position(this_pdf_file, that_position = 1) ⇒ Object
# === add_this_pdf_file_towards_that_position ========================================================================= #.
-
#add_to_the_favourites(i, be_verbose = true, &block) ⇒ Object
(also: #add, #add_this_to_the_favourites, #add_this_pdf_file)
# === add_to_the_favourites (add tag) ========================================================================= #.
-
#clear(into = into? ) ⇒ Object
# === clear ========================================================================= #.
-
#clear_old_books ⇒ Object
# === clear_old_books ========================================================================= #.
-
#consider_loading_and_sanitizing_the_timestamps_from_a_local_yaml_file(_ = store_the_timestamps_into_this_local_file? ) ⇒ Object
# === consider_loading_and_sanitizing_the_timestamps_from_a_local_yaml_file ========================================================================= #.
-
#convert_time_to_string(i) ⇒ Object
# === convert_time_to_string ========================================================================= #.
-
#current_favourite_books? ⇒ Boolean
# === current_favourite_books?.
-
#delete_this_favourite(i) ⇒ Object
# === delete_this_favourite ========================================================================= #.
-
#do_custom_reopen ⇒ Object
# === do_custom_reopen (custom tag).
-
#do_query_real ⇒ Object
# === do_query_real ========================================================================= #.
-
#do_reopen_all_tracked_pdf_files(i = yaml_location? ) ⇒ Object
# === do_reopen_all_tracked_pdf_files ========================================================================= #.
-
#elegantly_show_all_favourites(optional_arguments = nil, _ = favourite_books? ) ⇒ Object
(also: #do_query_favourites, #show_the_favourites)
# === elegantly_show_all_favourites.
-
#empty_favourites? ⇒ Boolean
(also: #no_favourites?)
# === empty_favourites? ========================================================================= #.
-
#exchange_these_two_positions(a, b) ⇒ Object
# === exchange_these_two_positions.
-
#favourite_books? ⇒ Boolean
(also: #favourites?, #favourite_books, #all_favourites?, #available_books?)
# === favourite_books?.
-
#handle_this_pseudo_regex(i) ⇒ Object
# === handle_this_pseudo_regex.
-
#inform_the_user_how_to_restore_the_books ⇒ Object
-
#initialize(commandline_arguments = ARGV, run_already = true, &block) ⇒ Books
constructor
# === initialize ========================================================================= #.
-
#into? ⇒ Boolean
(also: #yaml_location?, #yaml_file?)
# === into? ========================================================================= #.
-
#menu(i = commandline_arguments? ) ⇒ Object
-
#open_the_favourites(into = into? ) ⇒ Object
(also: #open, #open_the_pdf_files, #do_query_open)
# === open_the_favourites (open tag) ========================================================================= #.
-
#open_this_book_at_position(i) ⇒ Object
# === open_this_book_at_position.
-
#open_this_pdf_file(i) ⇒ Object
(also: #open_in_pdf_viewer)
# === open_this_pdf_file.
-
#remove_entry_at_position(position) ⇒ Object
# === remove_entry_at_position.
-
#remove_the_first_page_of_this_book(i) ⇒ Object
# === remove_the_first_page_of_this_book.
-
#remove_the_first_page_of_this_book_and_then_considering_showing_the_favourites(i) ⇒ Object
# === remove_the_first_page_of_this_book_and_then_considering_showing_the_favourites ========================================================================= #.
-
#remove_the_first_page_of_this_target(target_pdf_file) ⇒ Object
# === remove_the_first_page_of_this_target ========================================================================= #.
-
#renew_the_timestamps ⇒ Object
# === renew_the_timestamps.
-
#reset ⇒ Object
# === reset (reset tag) ========================================================================= #.
-
#restore_the_original_yaml_file ⇒ Object
(also: #do_restore_the_original_yaml_file)
# === restore_the_original_yaml_file This method will simply copy the default .yml file to its assumed target location.
-
#return_the_dataset_containing_all_favourite_books ⇒ Object
# === return_the_dataset_containing_all_favourite_books ========================================================================= #.
-
#run ⇒ Object
# === run (run tag) ========================================================================= #.
-
#show_help ⇒ Object
# === show_help (help tag) ========================================================================= #.
-
#show_the_pdf_viewer_in_user ⇒ Object
# === show_the_pdf_viewer_in_user.
-
#show_these_books(i = favourite_books?) ) ⇒ Object
# === show_these_books.
-
#store_the_favourites(use_these_favourites = favourites? ) ⇒ Object
(also: #store, #store_these_favourites, #save_the_favourites, #store_this_new_array)
# === store_the_favourites (store tag).
-
#store_the_timestamps_into_a_local_yaml_file(hash = ) ⇒ Object
# === store_the_timestamps_into_a_local_yaml_file ========================================================================= #.
-
#store_the_timestamps_into_this_local_file? ⇒ Boolean
# === store_the_timestamps_into_this_local_file? ========================================================================= #.
-
#the_stored_timestamps_of_all_opened_pdf_books_are_where? ⇒ Boolean
# === the_stored_timestamps_of_all_opened_pdf_books_are_where? ========================================================================= #.
-
#try_to_load_the_favourites(into = into? ) ⇒ Object
(also: #do_load_the_favourites, #reload_the_favourites)
# === try_to_load_the_favourites ========================================================================= #.
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
#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(commandline_arguments = ARGV, run_already = true, &block) ⇒ Books
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/roebe/classes/books/books.rb', line 51
def initialize(
commandline_arguments = ARGV,
run_already = true,
&block
)
reset
set_commandline_arguments(
commandline_arguments
)
if block_given?
yielded = yield
case yielded
when :dont_run_yet,
:do_not_run_yet
run_already = false
end
end
run if run_already
end
|
Instance Method Details
#add_this_pdf_file_towards_that_position(this_pdf_file, that_position = 1) ⇒ Object
#
add_this_pdf_file_towards_that_position
#
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
|
# File 'lib/roebe/classes/books/books.rb', line 601
def add_this_pdf_file_towards_that_position(
this_pdf_file,
that_position = 1
)
if this_pdf_file.include? '*'
this_pdf_file = Dir[this_pdf_file].first.to_s
end
real_index = that_position.to_i - 1
this_pdf_file = File.absolute_path(this_pdf_file) unless @internal_hash[:favourite_books].include? this_pdf_file
if File.exist? this_pdf_file
@internal_hash[:favourite_books].insert(real_index, this_pdf_file)
opne "Inserting at position #{that_position} next."
store_the_favourites
show_the_favourites
else
opne "No file exists at #{sfile(this_pdf_file)}."
end
end
end
|
#add_to_the_favourites(i, be_verbose = true, &block) ⇒ Object
Also known as:
add, add_this_to_the_favourites, add_this_pdf_file
#
add_to_the_favourites (add tag)
#
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
|
# File 'lib/roebe/classes/books/books.rb', line 338
def add_to_the_favourites(
i,
be_verbose = true,
&block
)
if block_given?
yielded = yield
case yielded
when :be_verbose
be_verbose = true
end
end
if i.include? '*' unless File.exist? i
i = Dir[i]
i = i.first
end
end
i = File.absolute_path(i)
unless @internal_hash[:favourite_books].include? i
if File.exist? i
if be_verbose
ogrey 'Adding the file'
orev "#{sfancy(i)} #{grey}to the favourites."
end
@internal_hash[:favourite_books] << i
store_the_favourites
else
opnn; no_file_exists_at(i)
end
end
end
|
#clear(into = into?
) ⇒ Object
155
156
157
158
159
160
161
162
|
# File 'lib/roebe/classes/books/books.rb', line 155
def clear(
into = into?
)
if File.exist? into
orev "Now deleting the #{File.extname(into)} file #{sfile(into)}#{rev}."
File.delete(into)
end
end
|
#clear_old_books ⇒ Object
167
168
169
170
|
# File 'lib/roebe/classes/books/books.rb', line 167
def clear_old_books
orev 'Clearing all old books first.'
clear
end
|
#consider_loading_and_sanitizing_the_timestamps_from_a_local_yaml_file(_ = store_the_timestamps_into_this_local_file?
) ⇒ Object
#
consider_loading_and_sanitizing_the_timestamps_from_a_local_yaml_file
#
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
|
# File 'lib/roebe/classes/books/books.rb', line 533
def consider_loading_and_sanitizing_the_timestamps_from_a_local_yaml_file(
_ = store_the_timestamps_into_this_local_file?
)
if File.empty?(_)
else
if _ and File.exist?(_)
begin
@internal_hash[:hash_store_the_timestamps] = YAML.load_file(_)
rescue Psych::DisallowedClass => error
pp error
opne "#{rev}The file at #{sfile(_)} #{rev}could not be loaded."
end
the_timestamps = @internal_hash[:hash_store_the_timestamps]
if the_timestamps
the_timestamps.each_pair {|key, inner_array|
first_entry = inner_array[0]
if first_entry.is_a? String
inner_array[0] = ::Time.parse(first_entry)
@internal_hash[:hash_store_the_timestamps][key] = inner_array
else
opne tomato('Invalid entry for ')+
steelblue(key)+' - it is not a String.'
opne 'The timestamps are kept here:'
e
e sfile(_)
e
end
}
end
end
end
end
|
#convert_time_to_string(i) ⇒ Object
#
convert_time_to_string
#
678
679
680
681
|
# File 'lib/roebe/classes/books/books.rb', line 678
def convert_time_to_string(i)
return i if i.is_a? String
return hh_mm_ss_day_month_year(i)
end
|
#current_favourite_books? ⇒ Boolean
#
current_favourite_books?
This will always return the first .pdf book.
#
204
205
206
|
# File 'lib/roebe/classes/books/books.rb', line 204
def current_favourite_books?
YAML.load_file(into?).first
end
|
#delete_this_favourite(i) ⇒ Object
#
delete_this_favourite
#
218
219
220
221
222
223
224
225
226
227
|
# File 'lib/roebe/classes/books/books.rb', line 218
def delete_this_favourite(i)
favourites = favourites?
if favourites.empty?
opne 'No .pdf book was assigned yet. Use --add to add a new entry.'
else
i = i.to_i - 1
favourites.delete_at(i)
store_these_favourites(favourites)
end
end
|
#do_custom_reopen ⇒ Object
#
do_custom_reopen (custom tag)
This is only for my home system.
#
399
400
401
402
403
404
405
406
|
# File 'lib/roebe/classes/books/books.rb', line 399
def do_custom_reopen
clear_old_books
add('/home/x/books/BASICS_Erste_Hilfe_by_Tobias_Matreitz_2013/BASICS_Erste_Hilfe_by_Tobias_Matreitz_2013.pdf')
add('/home/x/studium/UNI_WIEN/300078_Hominidenevolution/Alle_Folien_Hominidenevolution_2023W.pdf')
add('/home/x/books/The_Pragmatic_Programmer_20th_Anniversary_Edition_by_David_Thomas_Andrew_Hunt_2020/The_Pragmatic_Programmer_20th_Anniversary_Edition_by_David_Thomas_Andrew_Hunt_2020.pdf')
store_the_favourites
open_the_favourites
end
|
#do_query_real ⇒ Object
211
212
213
|
# File 'lib/roebe/classes/books/books.rb', line 211
def do_query_real
show_the_favourites(:full_path)
end
|
#do_reopen_all_tracked_pdf_files(i = yaml_location?
) ⇒ Object
#
do_reopen_all_tracked_pdf_files
#
382
383
384
385
386
387
388
389
390
391
392
|
# File 'lib/roebe/classes/books/books.rb', line 382
def do_reopen_all_tracked_pdf_files(
i = yaml_location?
)
if File.exist? i
YAML.load_file(i).each {|entry|
open_this_pdf_file(entry)
}
else
no_file_exists_at(i)
end
end
|
#elegantly_show_all_favourites(optional_arguments = nil, _ = favourite_books?
) ⇒ Object
Also known as:
do_query_favourites, show_the_favourites
#
elegantly_show_all_favourites
This method will show all favourite books.
This method, rewritten in January 2024, will make use of unicode horizontal bars, and also show more information than the old method did.
#
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
|
# File 'lib/roebe/classes/books/books.rb', line 723
def elegantly_show_all_favourites(
optional_arguments = nil, _ = favourite_books?
)
n_favourite_books = _.size
if _.empty? opne tomato('No .pdf books are available for the current library.')
opne tomato("Normally these would be found at the following location:")
e
e " #{sfile(yaml_location?)}"
e
if is_on_roebe?
inform_the_user_how_to_restore_the_books
end
else
n_pdf_pages_in_total = 0
unicode_horizontal_bar = EmojiParadise.unicode_horizontal_bar
e "#{rev}#{grey('The following ')}#{royalblue(_.size)} #{rev}"\
"#{grey('books are stored as favourites:')}"
e
e olivedrab(' Index | Title'\
' '\
'| n pages')
if SHOW_HOW_MANY_PAGES_ARE_IN_THAT_PDF_FILE
e olivedrab(unicode_horizontal_bar * 108)
end
_.each_with_index {|this_book, index| index += 1
absolute_path = File.absolute_path(this_book)
if @internal_hash[:hash_store_the_timestamps].has_key?(absolute_path)
else @internal_hash[:hash_store_the_timestamps][absolute_path] = []
if File.exist? absolute_path
@internal_hash[:hash_store_the_timestamps][absolute_path] <<
File.mtime(absolute_path)
end
end
if SHOW_HOW_MANY_PAGES_ARE_IN_THAT_PDF_FILE
current_array = @internal_hash[:hash_store_the_timestamps][absolute_path]
if current_array.size > 1 first = current_array.first if first.is_a?(String) else
if File.exist? absolute_path
modification = File.mtime(absolute_path) - first
end
begin
if modification and modification > 1
n_pages = ::PdfParadise.n_pages_in_this_pdf_file(this_book) { :be_quiet }
else
n_pages = current_array.last
end
rescue ArgumentError => error
pp error
e sfile(yaml_file?)
e sfile(the_stored_timestamps_of_all_opened_pdf_books_are_where?)
end
end
else
n_pages = ::PdfParadise.n_pages_in_this_pdf_file(this_book) { :be_quiet }
@internal_hash[:hash_store_the_timestamps][absolute_path] << n_pages
end
end
n_pdf_pages_in_total += n_pages.to_i
case optional_arguments
when :full_path
else
this_book = File.basename(this_book)
end
result = ' '.dup
result << ' ' if (n_favourite_books > 9) and (index < 10)
result << "#{green('(')}"\
"#{steelblue(index)}"\
"#{green(')')} #{olivedrab('|')} "\
"#{sfancy(this_book.ljust(86, ' '))}".dup
if SHOW_HOW_MANY_PAGES_ARE_IN_THAT_PDF_FILE
result << olivedrab(' |')+lightsteelblue(
" #{n_pages.to_s.rjust(3,' ')} pages"
)
end
result.prepend(' ')
e result }
if SHOW_HOW_MANY_PAGES_ARE_IN_THAT_PDF_FILE
e olivedrab(unicode_horizontal_bar * 108)
e royalblue(
(n_pdf_pages_in_total.to_s+' pages in total').
rjust(108)
)
end
e
store_the_timestamps_into_a_local_yaml_file
end
end
|
#empty_favourites? ⇒ Boolean
Also known as:
no_favourites?
861
862
863
|
# File 'lib/roebe/classes/books/books.rb', line 861
def empty_favourites?
favourites?.empty?
end
|
#exchange_these_two_positions(a, b) ⇒ Object
#
exchange_these_two_positions
This method will exchange two positions with one another.
#
413
414
415
416
417
418
419
420
421
422
423
424
425
426
|
# File 'lib/roebe/classes/books/books.rb', line 413
def exchange_these_two_positions(a, b)
opne grey('Now exchanging the two positions, index ')+
"#{steelblue(a)} #{rev}"+
grey('with index ')+
steelblue(b)+rev+
grey(" (swapping operation).")
a -= 1
b -= 1
new_array = favourite_books?.dup
old_value_of_b = new_array[b]
new_array[b] = new_array[a] new_array[a] = old_value_of_b
store_this_new_array(new_array)
end
|
#favourite_books? ⇒ Boolean
Also known as:
favourites?, favourite_books, all_favourites?, available_books?
#
favourite_books?
Query-method over @internal_hash, to return the Array keeping track of the favourite books.
#
851
852
853
|
# File 'lib/roebe/classes/books/books.rb', line 851
def favourite_books?
@internal_hash[:favourite_books]
end
|
#handle_this_pseudo_regex(i) ⇒ Object
#
handle_this_pseudo_regex
Only call this method after checking that the input starts with a ‘/’ and ends with a ‘/’.
This method will also remove a page from a .pdf file, but this will be based on matching against a search String that can be passed from the commandline.
Example for this:
books /Kemper/
#
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
|
# File 'lib/roebe/classes/books/books.rb', line 637
def handle_this_pseudo_regex(i)
i = i.dup if i.frozen?
i.chop!
i[0,1] = ''
regex = Regexp.new(i)
array = available_books?
selection = array.select {|entry|
entry = File.basename(entry)
entry =~ regex
}
if selection.empty?
opne 'No match was found for '+tomato(regex.to_s)
else
n_entries = selection.size
case n_entries
when 1
this_file = selection.first
remove_the_first_page_of_this_book_and_then_considering_showing_the_favourites(this_file)
else
e 'Unsure how to proceed, as we have '+n_entries.to_s+' matches.'
pp selection
end
end
end
|
703
704
705
706
707
708
709
710
711
|
# File 'lib/roebe/classes/books/books.rb', line 703
def inform_the_user_how_to_restore_the_books
e "#{rev}You can also use:"
e
e ' books --restore'
e
e 'To copy the old books.' e
end
|
#into? ⇒ Boolean
Also known as:
yaml_location?, yaml_file?
833
834
835
|
# File 'lib/roebe/classes/books/books.rb', line 833
def into?
"#{log_dir?}roebe/favourite_books.yml"
end
|
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
|
# File 'lib/roebe/classes/books/menu.rb', line 16
def (
i = commandline_arguments?
)
if i.is_a? Array
if i.empty?
if is_on_roebe?
show_the_favourites else
show_help
end
else
i.each {|entry| (entry) }
end
else
case i when /^-?-?custom(-|_)?reopen/i,
/^-?-?do(-|_)?custom(-|_)?reopen/i
do_custom_reopen
exit
when /^-?-?clear$/i,
/^-?-?reset$/i
clear
exit
when /^-?-?reopen/i,
/^-?-?restore/i,
/^-?-?open(-|_)?all/i
do_reopen_all_tracked_pdf_files
exit
when /^\d+$/ open_this_pdf_file(i)
exit
when /^-?-?restore$/i,
/^-?-?copy$/i
restore_the_original_yaml_file
exit
when /^-?-?recreate(-|_)the(-|_)book(-|_)index?/i
require 'roebe/classes/generate_overview_of_the_locally_available_books.rb'
Roebe::GenerateOverviewOfTheLocallyAvailableBooks.new
when /^-?-?remove(-|_)all(-|_)entries?/i
remove_entry_at_position(:remove_all_entries)
show_the_favourites
when /^-?-?remove(-|_)?entr?y=(.+)$/i, /^-?-?remove(-|_)?this(-|_)?entry=(.+)$/i position = $1.to_s.dup.to_i
position = $2.to_s.dup.to_i if $2
position = $3.to_s.dup.to_i if $3
remove_entry_at_position(position)
show_the_favourites
when /^-?-?add=(.+)$/i,
/^-?-?open=(.+)$/i
_ = $1.to_s.dup
add_this_pdf_file(_)
open_this_pdf_file(_)
exit
when /^-?-?add(-|_)?this(-|_)?to(-|_)?that(-|_)?entry=(.*)$/i _ = $5.to_s.dup if _.include? ','
splitted = _.split(',')
add_this_pdf_file_towards_that_position(*splitted)
else
opne "The input needs to include one ','."
end
exit
when /^-?-?path\??/i,
/^-?-?dir\??/i,
/^-?-?yaml(-|_)?file\??/i e steelblue(into?)
exit
when /^-?-?first=(.+)$/i,
/^-?-?delete(-|_)?the(-|_)?first(-|_)?page(-|_)?of=(.+)$/i, /^-?-?delete(-|_)?the(-|_)?first(-|_)?page(-|_)?of(-|_)?this(-|_)?book=(.+)$/i, /^-?-?remove(-|_)?pdf(-|_)?page(-|_)?of=(.+)$/i, /^-?-?remove(-|_)?first(-|_)?page(-|_)?from=(.+)$/i, /^-?-?remove(-|_)?pdf(-|_)?page(-|_)?from=(.+)$/i, /^-?-?remove(-|_)?first(-|_)?page(-|_)?=(.+)$/i, /^-?-?remove(-|_)?pdf(-|_)?page=(.+)$/i, /^-?-?remove(-|_)?first(-|_)?pdf(-|_)?page=(.+)$/i, /^-?-?remove=(.+)$/i number = $1.to_s.dup.to_i
number = $4.to_s.dup.to_i if $4
number = $5.to_s.dup.to_i if $5
number = $7.to_s.dup.to_i if $7
remove_the_first_page_of_this_book_and_then_considering_showing_the_favourites(number)
when /-?-?open=(\d{1,5},?\d{0,2},?\d{0,2},?\d{0,2},?\d{0,2},?\d{0,2},?\d{0,2})$/i,
/-?-?open(\d{1,5})$/i
_ = $1.to_s.dup
open_this_book_at_position(_)
exit
when /^-?-?renew(-|_)?the(-|_)?timestamps$/i
renew_the_timestamps
exit
when /^-?-?ex?change=(\d{1,3}),(\d{1,3})/i
exchange_these_two_positions($1.to_i, $2.to_i)
exit
when /^-?-?open$/i,
/^-?-?open(-|_)?the(-|_)?favourites$/i
open
exit
when /^-?-?real/i,
/^-?-?raw/i,
/^-?-?full(-|_)?path$/i,
/^-?-?full$/i
show_the_favourites(:full_path)
exit
when /^-?-?pdf(-|_)?viewer\??/i
show_the_pdf_viewer_in_user
exit
when /^-?-?add=(.+)/i
add_to_the_favourites($1.to_s.dup) { :be_verbose }
exit
when /^-?-?save$/i,
/^-?-?store$/i
store_the_favourites
when /^-?-?favourites/i,
/^-?-?show/i,
/^-?-?overview/i,
/^\?$/i
show_the_favourites
exit
when /^-?-?delete=(.+)$/i,
/^-?-?delete(-|_)?from(-|_)?favourites=(.+)$/i number = $1.to_s.dup.to_i
number = $3.to_s.dup.to_i if $3
delete_this_favourite(number)
when /^-?-?store$/i
store
exit
when /^-?-?help/i
show_help
exit
else
if i
if File.exist?(i) and i.end_with?('.pdf')
add_this_to_the_favourites(i)
open_this_pdf_file(all_favourites?)
elsif i.start_with?('--')
opne "#{rev}Not registered commandline flag: #{sfancy(i)}"
elsif i.start_with?('/') and i.end_with?('/')
handle_this_pseudo_regex(i)
else
opne "#{rev}Unclear what to do with: #{sfancy(i)}"
end
end
end
end
end
|
#open_the_favourites(into = into?
) ⇒ Object
Also known as:
open, open_the_pdf_files, do_query_open
#
open_the_favourites (open tag)
#
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
# File 'lib/roebe/classes/books/books.rb', line 182
def open_the_favourites(
into = into?
)
if File.exist? into
dataset = YAML.load_file(into)
ogrey "Next loading from #{sfile(into)} #{grey}a total of "\
"#{steelblue(dataset.size)} #{grey}.pdf files.#{rev}"
dataset.each {|this_file|
open_this_pdf_file(this_file)
}
else
no_file_exists_at(into)
end
end
|
#open_this_book_at_position(i) ⇒ Object
#
open_this_book_at_position
The input to this method can be a number, such as 5, but it can also be a Range, such as 5-8.
#
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
|
# File 'lib/roebe/classes/books/books.rb', line 279
def open_this_book_at_position(i)
if i.is_a? Array
i.each {|entry| open_this_book_at_position(entry) }
elsif i.is_a?(String) and i.include?(',')
open_this_book_at_position(i.split(','))
else
dataset = return_the_dataset_containing_all_favourite_books
if i.include? '-'
splitted = i.split('-')
min = splitted.first.to_i
max = splitted.last.to_i
min.upto(max) {|number|
entry = dataset[number.to_i - 1]
open_in_pdf_viewer(entry)
}
else
entry = dataset[i.to_i - 1]
open_in_pdf_viewer(entry)
end
end
end
|
#open_this_pdf_file(i) ⇒ Object
Also known as:
open_in_pdf_viewer
#
open_this_pdf_file
Delegate towards the open gem to open these pdf files.
#
688
689
690
691
692
693
694
695
696
697
698
|
# File 'lib/roebe/classes/books/books.rb', line 688
def open_this_pdf_file(i)
[i].flatten.each {|this_pdf_file|
case this_pdf_file
when /^\d+$/ this_pdf_file = @internal_hash[:favourite_books][this_pdf_file.to_i - 1]
end
::Open::Open.new(this_pdf_file) {{
open_via_fullscreen: TRY_TO_OPEN_PDF_FILES_IN_FULLSCREEN
}}
}
end
|
#remove_entry_at_position(position) ⇒ Object
#
remove_entry_at_position
Invocation example:
books --remove_entry=2
#
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
# File 'lib/roebe/classes/books/books.rb', line 114
def remove_entry_at_position(
position
)
if position.is_a? Symbol
case position
when :remove_all_entries
@internal_hash[:favourite_books].size.downto(0) {|entry|
remove_entry_at_position(entry+1)
}
else
opne 'Unknown symbol: :'+i.to_s
end
else
opne gold("Removing the entry at position ")+
steelblue(position)+
gold(" next.")
position = position.to_i - 1
@internal_hash[:favourite_books][position] = nil
@internal_hash[:favourite_books].compact!
save_the_favourites
end
end
|
#remove_the_first_page_of_this_book(i) ⇒ Object
#
remove_the_first_page_of_this_book
This method will remove the first page of a given .pdf file.
#
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
|
# File 'lib/roebe/classes/books/books.rb', line 433
def remove_the_first_page_of_this_book(
i
)
favourites = favourites?
if favourites.empty?
opne 'No .pdf book was assigned yet. Use --add to add a new entry.'
else
if i.is_a?(String) and File.exist?(i)
target_pdf_file = i
else
i = (i.to_i - 1)
target_pdf_file = favourites[i]
end
opne grey('Now removing the first page of this .pdf file (')+
steelblue(
n_pages_in_this_pdf_file?(target_pdf_file).to_s+
' pages currently'
)+grey('): ')
e
e " #{sfile(target_pdf_file)}"
e
::PdfParadise.remove_first_page_of_this_pdf_file(target_pdf_file) { :be_quiet }
end
end
|
#remove_the_first_page_of_this_book_and_then_considering_showing_the_favourites(i) ⇒ Object
#
remove_the_first_page_of_this_book_and_then_considering_showing_the_favourites
#
665
666
667
668
669
670
671
672
673
|
# File 'lib/roebe/classes/books/books.rb', line 665
def remove_the_first_page_of_this_book_and_then_considering_showing_the_favourites(
i
)
remove_the_first_page_of_this_book(i)
if is_on_roebe?
e show_the_favourites
end
end
|
#remove_the_first_page_of_this_target(target_pdf_file) ⇒ Object
#
remove_the_first_page_of_this_target
#
461
462
463
464
465
|
# File 'lib/roebe/classes/books/books.rb', line 461
def remove_the_first_page_of_this_target(
target_pdf_file
)
::PdfParadise.remove_first_page_of_this_pdf_file(target_pdf_file) { :be_quiet }
end
|
#renew_the_timestamps ⇒ Object
#
renew_the_timestamps
This method will always renew the timestamps.
Invocation example:
books --renew-the-timestamps
#
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
|
# File 'lib/roebe/classes/books/books.rb', line 580
def renew_the_timestamps
@internal_hash[:hash_store_the_timestamps] = {}
current_time = ::Time.now
_ = favourite_books?
_.each {|this_book|
absolute_path = File.absolute_path(this_book)
FileUtils.touch(absolute_path, mtime: current_time)
@internal_hash[:hash_store_the_timestamps][absolute_path] = []
@internal_hash[:hash_store_the_timestamps][absolute_path] << current_time
n_pages = ::PdfParadise.n_pages_in_this_pdf_file(this_book) { :be_quiet }
@internal_hash[:hash_store_the_timestamps][absolute_path] << n_pages
}
store_the_timestamps_into_a_local_yaml_file
end
|
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/roebe/classes/books/books.rb', line 80
def reset
super()
infer_the_namespace
@internal_hash[:favourite_books] = []
@internal_hash[:hash_store_the_timestamps] = {}
@internal_hash[:store_the_timestamps_into_this_local_file] =
the_stored_timestamps_of_all_opened_pdf_books_are_where?
consider_loading_and_sanitizing_the_timestamps_from_a_local_yaml_file
try_to_require_the_open_gem
try_to_load_the_favourites end
|
#restore_the_original_yaml_file ⇒ Object
Also known as:
do_restore_the_original_yaml_file
#
restore_the_original_yaml_file
This method will simply copy the default .yml file to its assumed target location.
#
482
483
484
485
486
487
488
489
490
491
|
# File 'lib/roebe/classes/books/books.rb', line 482
def restore_the_original_yaml_file
new_target = '/home/x/Temp/roebe/favourite_books.yml'
mkdir(File.dirname(new_target))
original_file = "#{project_base_dir?}yaml/books/favourite_books.yml"
if File.exist? original_file
opnn; copy_file(original_file, new_target) { :be_verbose }
else
opnn; no_file_exists_at(original_file)
end
end
|
#return_the_dataset_containing_all_favourite_books ⇒ Object
#
return_the_dataset_containing_all_favourite_books
#
175
176
177
|
# File 'lib/roebe/classes/books/books.rb', line 175
def return_the_dataset_containing_all_favourite_books
YAML.load_file(into?)
end
|
868
869
870
871
|
# File 'lib/roebe/classes/books/books.rb', line 868
def run
try_to_load_the_favourites if no_favourites?
end
|
#show_help ⇒ Object
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
|
# File 'lib/roebe/classes/books/books.rb', line 304
def show_help
erev
eparse ' books --clear # clear the old favourites'
eparse ' books --favourites # show all favourites'
eparse ' books --path? # show the path where the main .yml '\
'file is stored'
eparse ' books --open # open all .pdf files'
eparse ' books --open=2 # open only the .pdf file at entry #2'
eparse ' books --real # show the real path to the .pdf files'
eparse ' books --reopen # reopen all .pdf files that are '\
'registered; --open-all is an alias to this'
eparse ' books --store # store the favourites'
eparse ' books --restore # restore the default from the '+
steelblue('.yml')+
::Colours::Eparse.colour_right(' file (I tend to ')
e (' '*28)+
::Colours::Eparse.colour_left('# ')+
::Colours::Eparse.colour_right(
'do this after a fresh computer installation)')
eparse ' books --first=1 # remove the first page of the '\
'book stored at the given position'
eparse ' books --remove_entry=2 # remove the second entry from the '\
'list of favourites'
eparse ' books --exchange=6,1 # exchange entry at position 1 '\
'with position 6'
eparse ' books --add-this-to-that-entry=*pdf,4 # add a new .pdf file '\
'at position 4'
eparse ' books --renew-the-timestamps # Renew all timestamps'
e
end
|
#show_the_pdf_viewer_in_user ⇒ Object
#
show_the_pdf_viewer_in_user
This method can be used to show which .pdf viewer is in use.
#
234
235
236
|
# File 'lib/roebe/classes/books/books.rb', line 234
def show_the_pdf_viewer_in_user
e ::Open.pdf_viewer?
end
|
#show_these_books(i = favourite_books?)
) ⇒ Object
#
show_these_books
This method assumes an Array will be given.
#
472
473
474
|
# File 'lib/roebe/classes/books/books.rb', line 472
def show_these_books(i = favourite_books?)
show_the_favourites(nil, i)
end
|
#store_the_favourites(use_these_favourites = favourites?
) ⇒ Object
Also known as:
store, store_these_favourites, save_the_favourites, store_this_new_array
#
store_the_favourites (store tag)
This will store into “#Roebe::Base#log_dir?favourite_books.yml” by default.
#
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
|
# File 'lib/roebe/classes/books/books.rb', line 243
def store_the_favourites(
use_these_favourites = favourites?
)
what = YAML.dump(use_these_favourites)
into = into?
ogrey "Storing the current .pdf favourites ("+
lightblue("#{use_these_favourites.size} entries")+
grey(')')
opne grey('into `')+
sfile(into)+
grey('`.')
unless File.directory?(File.dirname(into))
mkdir(File.dirname(into))
end
write_what_into(what, into)
if is_on_roebe?
target_dir = '/home/x/programming/ruby/src/roebe/lib/roebe/yaml/books/'
into = target_dir+File.basename(into)
opne grey("Also storing into ")+sfile(into)+grey('.')
write_what_into(what, into)
end
end
|
#store_the_timestamps_into_a_local_yaml_file(hash = ) ⇒ Object
#
store_the_timestamps_into_a_local_yaml_file
#
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
|
# File 'lib/roebe/classes/books/books.rb', line 503
def store_the_timestamps_into_a_local_yaml_file(
hash = @internal_hash[:hash_store_the_timestamps]
)
this_hash_will_be_stored = {}
hash.each_pair {|key, inner_array|
first_entry = inner_array[0]
if File.exist? key
converted_time = convert_time_to_string(first_entry)
inner_array[0] = converted_time
this_hash_will_be_stored[key] = inner_array
else
opne 'No file could be found at '+sfile(key)+rev+'.'
opne 'This is currently disallowed. Please fix this problem'
opne 'before resuming the use of this class.'
end
}
what = YAML.dump(
@internal_hash[:hash_store_the_timestamps]
)
into = store_the_timestamps_into_this_local_file?
unless @internal_hash[:hash_store_the_timestamps].empty?
opne 'Storing the timestamps (last-modified time) into the file'
opne "#{rev}`#{sfile(into)}#{rev}`."
write_what_into(what, into)
end
end
|
#store_the_timestamps_into_this_local_file? ⇒ Boolean
#
store_the_timestamps_into_this_local_file?
#
496
497
498
|
# File 'lib/roebe/classes/books/books.rb', line 496
def store_the_timestamps_into_this_local_file?
@internal_hash[:store_the_timestamps_into_this_local_file]
end
|
#the_stored_timestamps_of_all_opened_pdf_books_are_where? ⇒ Boolean
#
the_stored_timestamps_of_all_opened_pdf_books_are_where?
#
841
842
843
|
# File 'lib/roebe/classes/books/books.rb', line 841
def the_stored_timestamps_of_all_opened_pdf_books_are_where?
roebe_log_directory?+'stored_timestamps_of_all_opened_pdf_books.yml'
end
|
#try_to_load_the_favourites(into = into?
) ⇒ Object
Also known as:
do_load_the_favourites, reload_the_favourites
#
try_to_load_the_favourites
#
143
144
145
146
147
148
149
|
# File 'lib/roebe/classes/books/books.rb', line 143
def try_to_load_the_favourites(
into = into?
)
if into and File.exist?(into)
@internal_hash[:favourite_books] = YAML.load_file(into)
end
end
|