Class: Extracter::Base
- Inherits:
-
Object
- Object
- Extracter::Base
- Defined in:
- lib/extracter/base/base.rb
Overview
Extracter::Base
Direct Known Subclasses
Instance Method Summary collapse
-
#are_we_on_windows? ⇒ Boolean
# === are_we_on_windows? ========================================================================= #.
-
#array_archive_types? ⇒ Boolean
# === array_archive_types? ========================================================================= #.
-
#be_verbose ⇒ Object
# === be_verbose ========================================================================= #.
-
#be_verbose? ⇒ Boolean
# === be_verbose?.
-
#change_directory(i) ⇒ Object
(also: #cd)
# === change_directory ========================================================================= #.
-
#check_whether_the_colours_gem_is_available ⇒ Object
# === check_whether_the_colours_gem_is_available ========================================================================= #.
-
#colour_to_use_for_directories? ⇒ Boolean
# === colour_to_use_for_directories? ========================================================================= #.
-
#commandline_arguments? ⇒ Boolean
# === commandline_arguments? ========================================================================= #.
-
#cpr(a, b) ⇒ Object
# === cpr ========================================================================= #.
-
#create_directory(i) ⇒ Object
(also: #mkdir)
# === create_directory (mkdir tag).
-
#create_the_internal_hash ⇒ Object
# === create_the_internal_hash ========================================================================= #.
-
#cyan?(use_colours = use_colours?) ) ⇒ Boolean
# === cyan ========================================================================= #.
-
#debug? ⇒ Boolean
# === debug? ========================================================================= #.
-
#disable_colours ⇒ Object
# === disable_colours.
-
#do_be_quiet ⇒ Object
(also: #be_silent, #be_quiet)
# === do_be_quiet ========================================================================= #.
-
#do_not_make_use_of_colours ⇒ Object
# === do_not_make_use_of_colours ========================================================================= #.
-
#do_try_to_use_colours ⇒ Object
# === do_try_to_use_colours ========================================================================= #.
-
#e(i = '') ⇒ Object
# === e (e tag) ========================================================================= #.
-
#enable_colours ⇒ Object
# === enable_colours ========================================================================= #.
-
#enable_debug ⇒ Object
# === enable_debug ========================================================================= #.
-
#ewarn(i = '', use_colours = use_colours? ) ⇒ Object
# === ewarn ========================================================================= #.
-
#first_argument? ⇒ Boolean
(also: #first?)
# === first_argument? ========================================================================= #.
-
#is_archive?(i) ⇒ Boolean
# === is_archive?.
-
#move(a, b) ⇒ Object
(also: #mv)
# === move ========================================================================= #.
-
#namespace? ⇒ Boolean
# === namespace? ========================================================================= #.
-
#opne(i = '') ⇒ Object
# === opne ========================================================================= #.
-
#opnn(use_this_hash = use_this_opn_hash? ) ⇒ Object
(also: #opn, #copn)
# === opnn.
-
#orev(i = '') ⇒ Object
# === orev ========================================================================= #.
-
#rds(i) ⇒ Object
# === rds ========================================================================= #.
-
#register_sigint(this_class_name = 'Extracter') ⇒ Object
# === register_sigint ========================================================================= #.
-
#remove_file_extension(i) ⇒ Object
(also: #remove_extension, #remove_ext)
# === remove_file_extension ========================================================================= #.
-
#remove_this_directory(i) ⇒ Object
# === remove_this_directory.
-
#reset ⇒ Object
# === reset (reset tag) ========================================================================= #.
-
#return_pwd ⇒ Object
# === return_pwd ========================================================================= #.
-
#rev ⇒ Object
# === rev (rev tag) ========================================================================= #.
-
#sdir(i = '') ⇒ Object
# === sdir ========================================================================= #.
-
#set_be_verbose(i = false) ⇒ Object
(also: #set_verbosity, #show_commands_used)
# === set_be_verbose.
-
#set_commandline_arguments(i = '') ⇒ Object
# === set_commandline_arguments ========================================================================= #.
-
#set_use_colours(i, main_hash = main_hash?) ) ⇒ Object
# === set_use_colours ========================================================================= #.
-
#set_use_opn(i = true) ⇒ Object
# === set_use_opn ========================================================================= #.
-
#sfancy(i = '') ⇒ Object
# === sfancy ========================================================================= #.
-
#sfile(i = '') ⇒ Object
# === sfile ========================================================================= #.
-
#simp(i = '', use_colours = use_colours? ) ⇒ Object
# === simp ========================================================================= #.
-
#steelblue(i = '', use_colours = use_colours? ) ⇒ Object
# === steelblue ========================================================================= #.
-
#tomato(i = '', use_colours = use_colours? ) ⇒ Object
# === tomato ========================================================================= #.
-
#try_to_require_fileutils ⇒ Object
# === try_to_require_fileutils ========================================================================= #.
-
#try_to_use_colours? ⇒ Boolean
(also: #use_colours?, #colours?)
# === try_to_use_colours?.
-
#use_opn? ⇒ Boolean
# === use_opn? ========================================================================= #.
-
#use_this_opn_hash? ⇒ Boolean
(also: #main_hash?)
# === use_this_opn_hash? ========================================================================= #.
Instance Method Details
#are_we_on_windows? ⇒ Boolean
#
are_we_on_windows?
#
231 232 233 |
# File 'lib/extracter/base/base.rb', line 231 def are_we_on_windows? ::Extracter.are_we_on_windows? end |
#array_archive_types? ⇒ Boolean
#
array_archive_types?
#
474 475 476 |
# File 'lib/extracter/base/base.rb', line 474 def array_archive_types? ARRAY_REGISTERED_ARCHIVES end |
#be_verbose ⇒ Object
#
be_verbose
#
289 290 291 |
# File 'lib/extracter/base/base.rb', line 289 def be_verbose set_be_verbose(true) end |
#be_verbose? ⇒ Boolean
#
be_verbose?
Getter method for whether we will be verbose or not.
#
240 241 242 |
# File 'lib/extracter/base/base.rb', line 240 def be_verbose? @internal_hash[:be_verbose] end |
#change_directory(i) ⇒ Object Also known as: cd
#
change_directory
#
92 93 94 |
# File 'lib/extracter/base/base.rb', line 92 def change_directory(i) Dir.chdir(i) end |
#check_whether_the_colours_gem_is_available ⇒ Object
#
check_whether_the_colours_gem_is_available
#
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/extracter/base/base.rb', line 71 def check_whether_the_colours_gem_is_available if Object.const_defined?(:Colours) and Colours.respond_to?(:simp) and Colours.respond_to?(:sfancy) and Colours.respond_to?(:sdir) and Colours.respond_to?(:simp) else do_not_make_use_of_colours end end |
#colour_to_use_for_directories? ⇒ Boolean
#
colour_to_use_for_directories?
#
259 260 261 262 263 264 265 |
# File 'lib/extracter/base/base.rb', line 259 def colour_to_use_for_directories? if use_colours? return @internal_hash[:colour_to_use_for_directories] else return '' end end |
#commandline_arguments? ⇒ Boolean
#
commandline_arguments?
#
340 341 342 |
# File 'lib/extracter/base/base.rb', line 340 def commandline_arguments? @commandline_arguments end |
#cpr(a, b) ⇒ Object
#
cpr
#
154 155 156 157 |
# File 'lib/extracter/base/base.rb', line 154 def cpr(a, b) try_to_require_fileutils FileUtils.cp_r(a, b) end |
#create_directory(i) ⇒ Object Also known as: mkdir
#
create_directory (mkdir tag)
Use this to create directories.
#
282 283 284 |
# File 'lib/extracter/base/base.rb', line 282 def create_directory(i) FileUtils.mkdir_p(i) unless File.directory?(i) end |
#create_the_internal_hash ⇒ Object
#
create_the_internal_hash
#
64 65 66 |
# File 'lib/extracter/base/base.rb', line 64 def create_the_internal_hash @internal_hash = {} end |
#cyan?(use_colours = use_colours?) ) ⇒ Boolean
#
cyan
#
99 100 101 102 |
# File 'lib/extracter/base/base.rb', line 99 def cyan?(use_colours = use_colours?) return Colours::CYAN if Object.const_defined?(:Colours) and use_colours return '' end |
#debug? ⇒ Boolean
#
debug?
#
361 362 363 |
# File 'lib/extracter/base/base.rb', line 361 def debug? @internal_hash[:debug] end |
#disable_colours ⇒ Object
#
disable_colours
Use this method if you want to disable colour-support of this class.
#
272 273 274 275 |
# File 'lib/extracter/base/base.rb', line 272 def disable_colours set_use_colours(false) @internal_hash[:colour_to_use_for_directories] = ''.dup end |
#do_be_quiet ⇒ Object Also known as: be_silent, be_quiet
#
do_be_quiet
#
296 297 298 |
# File 'lib/extracter/base/base.rb', line 296 def do_be_quiet set_be_verbose(false) end |
#do_not_make_use_of_colours ⇒ Object
#
do_not_make_use_of_colours
#
85 86 87 |
# File 'lib/extracter/base/base.rb', line 85 def do_not_make_use_of_colours @internal_hash[:use_colours] = false end |
#do_try_to_use_colours ⇒ Object
#
do_try_to_use_colours
#
402 403 404 |
# File 'lib/extracter/base/base.rb', line 402 def do_try_to_use_colours set_use_colours(true) end |
#e(i = '') ⇒ Object
#
e (e tag)
#
213 214 215 |
# File 'lib/extracter/base/base.rb', line 213 def e(i = '') puts i end |
#enable_colours ⇒ Object
#
enable_colours
#
382 383 384 385 |
# File 'lib/extracter/base/base.rb', line 382 def enable_colours set_use_colours(true) @internal_hash[:colour_to_use_for_directories] = cyan? end |
#enable_debug ⇒ Object
#
enable_debug
#
368 369 370 |
# File 'lib/extracter/base/base.rb', line 368 def enable_debug @internal_hash[:debug] = true end |
#ewarn(i = '', use_colours = use_colours? ) ⇒ Object
#
ewarn
#
140 141 142 143 144 145 146 147 148 149 |
# File 'lib/extracter/base/base.rb', line 140 def ewarn( i = '', use_colours = use_colours? ) if use_colours and Object.const_defined?(:Colours) e Colours.swarn(i) else e i end end |
#first_argument? ⇒ Boolean Also known as: first?
#
first_argument?
#
347 348 349 |
# File 'lib/extracter/base/base.rb', line 347 def first_argument? @commandline_arguments.first end |
#is_archive?(i) ⇒ Boolean
#
is_archive?
This method queries whether the given file at hand (as input to this method) is assumed to be an archive or whether it is not.
#
465 466 467 468 469 |
# File 'lib/extracter/base/base.rb', line 465 def is_archive?(i) ARRAY_ARCHIVE_TYPES.include?( File.extname(File.basename(i)) ) end |
#move(a, b) ⇒ Object Also known as: mv
#
move
#
162 163 164 165 |
# File 'lib/extracter/base/base.rb', line 162 def move(a, b) try_to_require_fileutils FileUtils.mv(a, b) end |
#namespace? ⇒ Boolean
#
namespace?
#
375 376 377 |
# File 'lib/extracter/base/base.rb', line 375 def namespace? @internal_hash[:namespace] end |
#opne(i = '') ⇒ Object
#
opne
#
434 435 436 |
# File 'lib/extracter/base/base.rb', line 434 def opne(i = '') opnn; e i end |
#opnn(use_this_hash = use_this_opn_hash? ) ⇒ Object Also known as: opn, copn
#
opnn
This variant will also check whether we should show the name or not.
#
450 451 452 453 454 455 456 |
# File 'lib/extracter/base/base.rb', line 450 def opnn( use_this_hash = use_this_opn_hash? ) if use_opn? and Object.const_defined?(:Opn) Opn.opn(use_this_hash) end end |
#orev(i = '') ⇒ Object
#
orev
#
481 482 483 |
# File 'lib/extracter/base/base.rb', line 481 def orev(i = '') opne "#{rev}#{i}" end |
#rds(i) ⇒ Object
#
rds
#
304 305 306 307 |
# File 'lib/extracter/base/base.rb', line 304 def rds(i) return i.squeeze('/') if i.respond_to? :squeeze return i end |
#register_sigint(this_class_name = 'Extracter') ⇒ Object
#
register_sigint
#
247 248 249 250 251 252 253 254 |
# File 'lib/extracter/base/base.rb', line 247 def register_sigint(this_class_name = 'Extracter') Signal.trap('SIGINT') { e sfancy('Requesting a graceful exit from ')+ colour_to_use_for_directories?+ 'class '+this_class_name+sfancy('. Exiting now.') exit } end |
#remove_file_extension(i) ⇒ Object Also known as: remove_extension, remove_ext
#
remove_file_extension
#
323 324 325 326 |
# File 'lib/extracter/base/base.rb', line 323 def remove_file_extension(i) _ = File.basename(i) return ::Extracter.remove_archive_type(_) end |
#remove_this_directory(i) ⇒ Object
#
remove_this_directory
This method can be used to remove a directory.
#
172 173 174 175 176 177 |
# File 'lib/extracter/base/base.rb', line 172 def remove_this_directory(i) if File.directory? i try_to_require_fileutils FileUtils.rm_r(i) unless i == '/' end end |
#reset ⇒ Object
#
reset (reset tag)
#
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 |
# File 'lib/extracter/base/base.rb', line 31 def reset # ======================================================================= # # === @internal_hash # # The internal Hash must be created first. # ======================================================================= # create_the_internal_hash # ======================================================================= # # === :debug # ======================================================================= # @internal_hash[:debug] = false # ======================================================================= # # === :be_verbose # ======================================================================= # @internal_hash[:be_verbose] = true # ======================================================================= # # === :colour_to_use_for_directories # ======================================================================= # @internal_hash[:colour_to_use_for_directories] = 'cyan' # ======================================================================= # # === :use_opn # ======================================================================= # @internal_hash[:use_opn] = true # ← Whether to use make use of Opn by default or not. # ======================================================================= # # Next check whether the Colours gem is available. # ======================================================================= # check_whether_the_colours_gem_is_available do_try_to_use_colours end |
#return_pwd ⇒ Object
#
return_pwd
#
354 355 356 |
# File 'lib/extracter/base/base.rb', line 354 def return_pwd "#{Dir.pwd}/".squeeze('/') end |
#rev ⇒ Object
#
rev (rev tag)
#
220 221 222 223 224 225 226 |
# File 'lib/extracter/base/base.rb', line 220 def rev if use_colours? ::Colours.rev else '' end end |
#sdir(i = '') ⇒ Object
#
sdir
#
205 206 207 208 |
# File 'lib/extracter/base/base.rb', line 205 def sdir(i = '') return Colours.sdir(i) if use_colours? return i end |
#set_be_verbose(i = false) ⇒ Object Also known as: set_verbosity, show_commands_used
#
set_be_verbose
This sets the verbosity level of the class. Use only this method when you wish to modify the @be_verbose instance variable.
#
315 316 317 |
# File 'lib/extracter/base/base.rb', line 315 def set_be_verbose(i = false) @internal_hash[:be_verbose] = i end |
#set_commandline_arguments(i = '') ⇒ Object
#
set_commandline_arguments
#
332 333 334 335 |
# File 'lib/extracter/base/base.rb', line 332 def set_commandline_arguments(i = '') i = [i].flatten.compact @commandline_arguments = i end |
#set_use_colours(i, main_hash = main_hash?) ) ⇒ Object
#
set_use_colours
#
390 391 392 393 394 395 396 397 |
# File 'lib/extracter/base/base.rb', line 390 def set_use_colours(i, main_hash = main_hash?) # ======================================================================= # # We must also sync this towards our main Hash, for opn(). The next # line of code achieves precisely that. # ======================================================================= # main_hash.update(use_colours: i) if main_hash @internal_hash[:try_to_use_colours] = i end |
#set_use_opn(i = true) ⇒ Object
#
set_use_opn
#
420 421 422 |
# File 'lib/extracter/base/base.rb', line 420 def set_use_opn(i = true) @internal_hash[:use_opn] = i end |
#sfancy(i = '') ⇒ Object
#
sfancy
#
197 198 199 200 |
# File 'lib/extracter/base/base.rb', line 197 def sfancy(i = '') return Colours.sfancy(i) if use_colours? return i end |
#sfile(i = '') ⇒ Object
#
sfile
#
189 190 191 192 |
# File 'lib/extracter/base/base.rb', line 189 def sfile(i = '') return Colours.sfancy(i) if use_colours? return i end |
#simp(i = '', use_colours = use_colours? ) ⇒ Object
#
simp
#
118 119 120 121 122 123 124 |
# File 'lib/extracter/base/base.rb', line 118 def simp( i = '', use_colours = use_colours? ) return Colours.simp(i) if use_colours return i end |
#steelblue(i = '', use_colours = use_colours? ) ⇒ Object
#
steelblue
#
129 130 131 132 133 134 135 |
# File 'lib/extracter/base/base.rb', line 129 def steelblue( i = '', use_colours = use_colours? ) return ::Colours.steelblue(i) if use_colours and ::Colours.respond_to?(:steelblue) return i end |
#tomato(i = '', use_colours = use_colours? ) ⇒ Object
#
tomato
#
107 108 109 110 111 112 113 |
# File 'lib/extracter/base/base.rb', line 107 def tomato( i = '', use_colours = use_colours? ) return Colours.tomato(i) if use_colours return i end |
#try_to_require_fileutils ⇒ Object
#
try_to_require_fileutils
#
182 183 184 |
# File 'lib/extracter/base/base.rb', line 182 def try_to_require_fileutils require 'fileutils' unless Object.const_defined?(:FileUtils) end |
#try_to_use_colours? ⇒ Boolean Also known as: use_colours?, colours?
#
try_to_use_colours?
Determine whether we will use colours for class Extracter::Base and its subclass.
#
412 413 414 |
# File 'lib/extracter/base/base.rb', line 412 def try_to_use_colours? @internal_hash[:try_to_use_colours] end |
#use_opn? ⇒ Boolean
#
use_opn?
#
427 428 429 |
# File 'lib/extracter/base/base.rb', line 427 def use_opn? @internal_hash[:use_opn] end |
#use_this_opn_hash? ⇒ Boolean Also known as: main_hash?
#
use_this_opn_hash?
#
441 442 443 |
# File 'lib/extracter/base/base.rb', line 441 def use_this_opn_hash? @internal_hash[:use_this_opn_hash] end |