Class: PdfParadise::SetMainBook
- Inherits:
-
Base
- Object
- Base
- PdfParadise::SetMainBook
show all
- Defined in:
- lib/pdf_paradise/set_main_book.rb
Overview
Constant Summary
collapse
- NAMESPACE =
inspect
- FILE_ROEBERIA_SETTINGS =
#
FILE_ROEBERIA_SETTINGS
#
'/home/x/data/personal/yaml/roeberia_settings.yml'
Class Method Summary
collapse
-
.[](i = '') ⇒ Object
# === PdfParadise::SetMainBook[] ========================================================================= #.
Instance Method Summary
collapse
Methods inherited from Base
#basename, #be_verbose?, #change_directory, #commandline_arguments?, #copy_file, #delete_file, #e, #ecomment, #esystem, #first_argument?, #gold, #infer_the_namespace, #input_without_leading_hyphens?, #internal_hash?, #is_an_image_file?, #is_on_roebe?, #lightsteelblue, #log_dir?, #mkdir, #mv, #n_pages?, #namespace?, #no_file_at, #opne, #opnn, #orange, #reset_the_internal_hash, #return_commandline_arguments_starting_with_hyphens, #return_files_from_the_commandline_arguments, #return_pwd, #rev, #set_be_quiet, #steelblue, #try_to_ensure_that_this_directory_exists, #write_what_into
Constructor Details
#initialize(commandline_arguments = nil, run_already = true) ⇒ SetMainBook
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/pdf_paradise/set_main_book.rb', line 40
def initialize(
commandline_arguments = nil,
run_already = true
)
reset
set_commandline_arguments(
commandline_arguments
)
run if run_already
end
|
Class Method Details
.[](i = '') ⇒ Object
#
PdfParadise::SetMainBook[]
#
148
149
150
|
# File 'lib/pdf_paradise/set_main_book.rb', line 148
def self.[](i = '')
new(i)
end
|
Instance Method Details
#consider_sanitizing_the_first_argument ⇒ Object
#
consider_sanitizing_the_first_argument
This method currently only makes sure that the argument given to this class will have the proper full path.
#
77
78
79
80
81
82
83
|
# File 'lib/pdf_paradise/set_main_book.rb', line 77
def consider_sanitizing_the_first_argument
if @commandline_arguments.first
unless @commandline_arguments.first.include? '/'
@commandline_arguments[0] = return_pwd+File.basename(@commandline_arguments[0])
end
end
end
|
#modify_this_file(this_file = FILE_ROEBERIA_SETTINGS) ⇒ Object
#
modify_this_file
This method will modify the file at hand, which is typically a .yml file (aka “roeberia_settings.yml”).
Call this method after you have made sure that the file at hand DOES exist.
#
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
|
# File 'lib/pdf_paradise/set_main_book.rb', line 94
def modify_this_file(
this_file = FILE_ROEBERIA_SETTINGS
)
seek_this_word = 'MAIN_BOOK'
require 'find_line_in_file'
result = FindLineInFile[
search_term: seek_this_word,
where: this_file
]
n_padding = 23 dataset = File.readlines(this_file)
line = dataset[result - 1]
if line.include? seek_this_word
padding = ' ' * (n_padding - ('MAIN_BOOK:'.size))
line = "MAIN_BOOK:"\
"#{padding}"\
"#{first_argument?}"
target = '/home/Temp/'+File.basename(this_file)
e "Backing up the old file next, onto `#{sfile(target)}`."
FileUtils.copy(this_file, target)
dataset[result - 1] = line
unless dataset.last == "\n"
dataset << "\n" end
write_what_into(dataset, this_file)
else
e "The line does not include our search "\
"term #{sfancy(seek_this_word)}."
end
end
|
#reset ⇒ Object
54
55
56
57
58
59
60
|
# File 'lib/pdf_paradise/set_main_book.rb', line 54
def reset
super()
@namespace = NAMESPACE
end
|
#run ⇒ Object
131
132
133
134
135
136
137
138
139
140
141
142
143
|
# File 'lib/pdf_paradise/set_main_book.rb', line 131
def run
first_argument = first_argument?
if first_argument and File.file?(first_argument)
opnn; e rev+
'Next assigning the file '+sfile(first_argument)
opnn; e 'to be the new main .pdf file.'
if File.exist? FILE_ROEBERIA_SETTINGS
modify_this_file(FILE_ROEBERIA_SETTINGS)
else
e 'No file exists at '+sfile(FILE_ROEBERIA_SETTINGS)+'.'
end
end
end
|
#set_commandline_arguments(i = '') ⇒ Object
#
set_commandline_arguments
#
65
66
67
68
69
|
# File 'lib/pdf_paradise/set_main_book.rb', line 65
def set_commandline_arguments(i = '')
i = [i].flatten.compact
@commandline_arguments = i
consider_sanitizing_the_first_argument
end
|