Class: Extracter::ExtractIt
- Inherits:
-
Base
- Object
- Base
- Extracter::ExtractIt
show all
- Defined in:
- lib/extracter/extract_it/extract_it.rb
Overview
Constant Summary
collapse
- NAMESPACE =
inspect
- ARRAY_ARCHIVE_TYPES =
#
Register the available (and handled) archive types here.
#
::Extracter::ARRAY_REGISTERED_ARCHIVES
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#change_directory, #check_whether_the_colours_gem_is_available, #cpr, #cyan?, #e, #ewarn, #move, #remove_this_directory, #rev, #sdir, #sfancy, #sfile, #simp, #steelblue, #tomato, #use_colours?
Constructor Details
#initialize(optional_set_input = nil, run_already = true) ⇒ ExtractIt
42
43
44
45
46
47
48
49
|
# File 'lib/extracter/extract_it/extract_it.rb', line 42
def initialize(
optional_set_input = nil,
run_already = true
)
reset
set_input(optional_set_input)
run if run_already
end
|
Class Method Details
.[](i = '') ⇒ Object
224
225
226
|
# File 'lib/extracter/extract_it/extract_it.rb', line 224
def self.[](i = '')
new(i)
end
|
Instance Method Details
#be_silent ⇒ Object
114
115
116
|
# File 'lib/extracter/extract_it/extract_it.rb', line 114
def be_silent
@be_silent = true
end
|
#be_verbose ⇒ Object
Also known as:
show_commands_used
121
122
123
|
# File 'lib/extracter/extract_it/extract_it.rb', line 121
def be_verbose
@be_silent = false
end
|
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/extracter/extract_it/extract_it.rb', line 162
def
pp @input if @debug
@input.each {|entry|
to_this_dir = Dir.pwd
to_this_dir << '/' unless to_this_dir.end_with? '/'
unless File.exist? entry
entry = try_to_glob_on(entry)
end
Extracter.(
entry,
to_this_dir
) {{ be_verbose: @be_silent }}
_ = ::Extracter.remove_file_suffix(entry)
if File.exist? entry
= to_this_dir+_
ARRAY_ARCHIVE_TYPES.each {|extension_name|
if .include? extension_name
quoted = Regexp.quote(extension_name)
.sub!(/#{quoted}$/,'')
end
}
if File.exist?() and
!(entry == )
opn; e "#{rev}Finished extracting "\
"#{sfile(_)}#{rev} to `#{sdir(to_this_dir)}#{rev}`."
else
opn; e "#{rev}No file called `#{sfile()}"\
"#{rev}` appears to exist."
end
end
}
end
|
#is_archive?(i) ⇒ Boolean
208
209
210
211
212
|
# File 'lib/extracter/extract_it/extract_it.rb', line 208
def is_archive?(i)
ARRAY_ARCHIVE_TYPES.include?(
File.extname(File.basename(i))
)
end
|
128
129
130
131
132
133
134
135
136
|
# File 'lib/extracter/extract_it/extract_it.rb', line 128
def notify_the_user_that_no_input_was_given_but_this_file_was_found(
this_file
)
opn; e "No input was given to #{sfancy(NAMESPACE)} but a "\
".zip file was"
opn; e 'found in this directory ('+sdir(Dir.pwd)+'): '+
sfancy(this_file)
opn; e 'We will use this zip file.'
end
|
#reset ⇒ Object
54
55
56
57
58
59
60
|
# File 'lib/extracter/extract_it/extract_it.rb', line 54
def reset
super()
@debug = false
end
|
#run ⇒ Object
217
218
219
|
# File 'lib/extracter/extract_it/extract_it.rb', line 217
def run
end
|
#
We will work on an Array as value to @input, at the end of this method.
#
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
|
# File 'lib/extracter/extract_it/extract_it.rb', line 79
def set_input(i = N)
case i
when /-?-?help$/i show_help
exit
end
i = [i] if i.is_a? String if @debug
opn; e 'The input given to us is: `'+sfile(i)+'`'
end
if i.is_a?(Array) and i.empty?
is_there_a_zip_file = Dir['*.zip']
unless is_there_a_zip_file.empty?
use_this_zip_file = is_there_a_zip_file.first
notify_the_user_that_no_input_was_given_but_this_file_was_found(use_this_zip_file)
i << use_this_zip_file
end
is_there_at_the_least_one_tar_xz_file = Dir['*.tar.xz']
unless is_there_at_the_least_one_tar_xz_file.empty?
i << is_there_at_the_least_one_tar_xz_file.first
end
end
@input = i end
|
#show_help ⇒ Object
65
66
67
68
69
70
71
|
# File 'lib/extracter/extract_it/extract_it.rb', line 65
def show_help
e 'We will show a little bit help, then exit.'
e
e 'To extract .tar.xz, do:'
e
efancy ' → tar -xJf *.tar.xz'
end
|
#try_to_glob_on(i) ⇒ Object
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
# File 'lib/extracter/extract_it/extract_it.rb', line 141
def try_to_glob_on(i)
result = Dir["#{i}*"]
result = result.partition {|entry| is_archive?(entry) }
result.flatten!
unless result.empty?
i = result.first
opn; e "#{rev}No result could be found for the given input, "\
"thus using #{sfancy(i)} #{rev}instead."
end
i
end
|