Class: Roebe::ReplaceSpaceWithUnderscore
- Inherits:
-
Base
show all
- Defined in:
- lib/roebe/classes/replace_space_with_underscore/replace_space_with_underscore.rb
Overview
Roebe::ReplaceSpaceWithUnderscore
Constant Summary
collapse
- REPLACE_WHICH_CHARACTER =
#
REPLACE_WHICH_CHARACTER
We will seek this character in the target file/directory.
#
' '
- REPLACE_WITH_THIS_CHARACTER =
#
REPLACE_WITH_THIS_CHARACTER
And we will replace it with this character.
#
'_'
- WORK_ON_DIRECTORIES_AS_WELL =
#
WORK_ON_DIRECTORIES_AS_WELL
Whether this class will include directories by default or whether it will not.
By default this will be false.
#
false
- GET_RID_OF_COMMA =
#
GET_RID_OF_COMMA
If the constant GET_RID_OF_COMMA is set to true, then this class will replace all occurences of ‘,’ with ”.
#
true
Constants inherited
from Base
Base::COLOURS, Base::HOME_DIRECTORY_OF_USER_X, Base::N, Base::NAMESPACE
Class Method Summary
collapse
-
.[](i = ARGV) ⇒ Object
# === Roebe::ReplaceSpaceWithUnderscore[] ========================================================================= #.
Instance Method Summary
collapse
-
#append_this_to_the_modified_entries(i) ⇒ Object
# === append_this_to_the_modified_entries ========================================================================= #.
-
#append_to_the_array_remove_these_strings_completely(i) ⇒ Object
# === append_to_the_array_remove_these_strings_completely ========================================================================= #.
-
#append_work_on_these_entries(i) ⇒ Object
(also: #append_this_entry)
# === append_work_on_these_entries ========================================================================= #.
-
#array_remove_these_strings_completely? ⇒ Boolean
# === array_remove_these_strings_completely? ========================================================================= #.
-
#array_these_entries_were_modified? ⇒ Boolean
(also: #which_files_were_modified?, #array_modified_these_files?, #modified_these_files, #modified_files?)
# === array_these_entries_were_modified?.
-
#consider_notifying_the_user_that_we_are_done_now ⇒ Object
# === consider_notifying_the_user_that_we_are_done_now.
-
#do_get_rid_of_all_underscores ⇒ Object
# === do_get_rid_of_all_underscores ========================================================================= #.
-
#do_get_rid_of_parens ⇒ Object
# === do_get_rid_of_parens ========================================================================= #.
-
#do_not_work_on_files ⇒ Object
(also: #do_not_work_on_any_files)
# === do_not_work_on_files ========================================================================= #.
-
#do_remove_commas ⇒ Object
# === do_remove_commas ========================================================================= #.
-
#do_replace_this_entry(this_entry, new_filename = File.basename(this_entry). tr(' ', replace_with_this_character?)) ⇒ Object
# === do_replace_this_entry.
-
#do_work_on_directories ⇒ Object
# === do_work_on_directories ========================================================================= #.
-
#get_rid_of_all_underscores? ⇒ Boolean
# === get_rid_of_all_underscores? ========================================================================= #.
-
#get_rid_of_apostrophes? ⇒ Boolean
# === get_rid_of_apostrophes? ========================================================================= #.
-
#get_rid_of_parens? ⇒ Boolean
# === get_rid_of_parens? ========================================================================= #.
-
#include_subdirectories_as_well? ⇒ Boolean
# === include_subdirectories_as_well? ========================================================================= #.
-
#initialize(commandline_arguments = ARGV, run_already = true) ⇒ ReplaceSpaceWithUnderscore
constructor
# === initialize ========================================================================= #.
-
#iterate_through_the_relevant_entries(token_to_use = token?, , work_on_these_entries = work_on_these_entries?, , be_verbose = be_verbose? ) ⇒ Object
(also: #run_for_real, #do_process_all_given_files, #batch_rename_all_files)
# === iterate_through_the_relevant_entries (main tag, rename tag).
-
#menu(i = commandline_arguments? ) ⇒ Object
-
#notify_the_user_that_we_have_finished? ⇒ Boolean
# === notify_the_user_that_we_have_finished? ========================================================================= #.
-
#obtain_all_relevant_entries ⇒ Object
# === obtain_all_relevant_entries ========================================================================= #.
-
#remove_commas? ⇒ Boolean
# === remove_commas? ========================================================================= #.
-
#replace_which_character? ⇒ Boolean
# === replace_which_character? ========================================================================= #.
-
#replace_with_this_character? ⇒ Boolean
(also: #replacement_char?, #replace_with_which_character?, #token?)
# === replace_with_this_character?.
-
#reset ⇒ Object
# === reset (reset tag) ========================================================================= #.
-
#run ⇒ Object
# === run (run tag) ========================================================================= #.
-
#set_default_token ⇒ Object
# === set_default_token ========================================================================= #.
-
#set_replace_which_character(i = :default) ⇒ Object
(also: #replace_this_character=, #replace_which_character=)
# === set_replace_which_character ========================================================================= #.
-
#set_replace_with_this_character(i = REPLACE_WITH_THIS_CHARACTER, be_verbose = be_verbose? ) ⇒ Object
(also: #set_token)
# === set_replace_with_this_character ========================================================================= #.
-
#set_work_on_these_entries(i) ⇒ Object
(also: #set_work_on_these_files, #set_file, #set_files)
# === set_work_on_these_entries.
-
#show_help ⇒ Object
# === show_help (help tag).
-
#simulate_only? ⇒ Boolean
# === simulate_only? ========================================================================= #.
-
#work_on_directories? ⇒ Boolean
# === work_on_directories? ========================================================================= #.
-
#work_on_files? ⇒ Boolean
# === work_on_files? ========================================================================= #.
-
#work_on_these_entries? ⇒ Boolean
(also: #work_on_these_files?, #files?, #obtain_the_files)
# === work_on_these_entries?.
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) ⇒ ReplaceSpaceWithUnderscore
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/roebe/classes/replace_space_with_underscore/replace_space_with_underscore.rb', line 65
def initialize(
commandline_arguments = ARGV,
run_already = true
)
reset
set_commandline_arguments(commandline_arguments)
case run_already
when :do_not_run_yet,
:dont_run_yet
run_already = false
end
run if run_already
end
|
Class Method Details
.[](i = ARGV) ⇒ Object
#
Roebe::ReplaceSpaceWithUnderscore[]
#
840
841
842
|
# File 'lib/roebe/classes/replace_space_with_underscore/replace_space_with_underscore.rb', line 840
def self.[](i = ARGV)
new(i)
end
|
Instance Method Details
#append_this_to_the_modified_entries(i) ⇒ Object
#
append_this_to_the_modified_entries
#
212
213
214
|
# File 'lib/roebe/classes/replace_space_with_underscore/replace_space_with_underscore.rb', line 212
def append_this_to_the_modified_entries(i)
@internal_hash[:array_these_entries_were_modified] << i
end
|
#append_to_the_array_remove_these_strings_completely(i) ⇒ Object
#
append_to_the_array_remove_these_strings_completely
#
219
220
221
|
# File 'lib/roebe/classes/replace_space_with_underscore/replace_space_with_underscore.rb', line 219
def append_to_the_array_remove_these_strings_completely(i)
@internal_hash[:array_remove_these_strings_completely] << i
end
|
#append_work_on_these_entries(i) ⇒ Object
Also known as:
append_this_entry
#
append_work_on_these_entries
#
473
474
475
476
477
|
# File 'lib/roebe/classes/replace_space_with_underscore/replace_space_with_underscore.rb', line 473
def append_work_on_these_entries(i)
@internal_hash[:work_on_these_entries] << i
@internal_hash[:work_on_these_entries].flatten!
@internal_hash[:work_on_these_entries].compact!
end
|
#array_remove_these_strings_completely? ⇒ Boolean
#
array_remove_these_strings_completely?
#
394
395
396
|
# File 'lib/roebe/classes/replace_space_with_underscore/replace_space_with_underscore.rb', line 394
def array_remove_these_strings_completely?
@internal_hash[:array_remove_these_strings_completely]
end
|
#array_these_entries_were_modified? ⇒ Boolean
Also known as:
which_files_were_modified?, array_modified_these_files?, modified_these_files, modified_files?
#
array_these_entries_were_modified?
This method will always return an Array. This Array keeps track as to which files were replaced.
#
185
186
187
|
# File 'lib/roebe/classes/replace_space_with_underscore/replace_space_with_underscore.rb', line 185
def array_these_entries_were_modified?
@internal_hash[:array_these_entries_were_modified]
end
|
#consider_notifying_the_user_that_we_are_done_now ⇒ Object
#
consider_notifying_the_user_that_we_are_done_now
This method is called last from within .run().
#
197
198
199
200
201
202
203
204
205
206
207
|
# File 'lib/roebe/classes/replace_space_with_underscore/replace_space_with_underscore.rb', line 197
def consider_notifying_the_user_that_we_are_done_now
if notify_the_user_that_we_have_finished?
_ = gold('Done!'.dup) unless modified_files?.empty?
_ << "#{rev} A total of "\
"#{royalblue(array_these_entries_were_modified?.size.to_s)}"\
"#{rev} files/directories were modified."
end
e _
end
end
|
#do_get_rid_of_all_underscores ⇒ Object
#
do_get_rid_of_all_underscores
#
784
785
786
|
# File 'lib/roebe/classes/replace_space_with_underscore/replace_space_with_underscore.rb', line 784
def do_get_rid_of_all_underscores
@internal_hash[:get_rid_of_all_underscores] = true
end
|
#do_get_rid_of_parens ⇒ Object
524
525
526
|
# File 'lib/roebe/classes/replace_space_with_underscore/replace_space_with_underscore.rb', line 524
def do_get_rid_of_parens
@internal_hash[:get_rid_of_parens] = true
end
|
#do_not_work_on_files ⇒ Object
Also known as:
do_not_work_on_any_files
401
402
403
|
# File 'lib/roebe/classes/replace_space_with_underscore/replace_space_with_underscore.rb', line 401
def do_not_work_on_files
@internal_hash[:work_on_files] = false
end
|
#do_remove_commas ⇒ Object
161
162
163
|
# File 'lib/roebe/classes/replace_space_with_underscore/replace_space_with_underscore.rb', line 161
def do_remove_commas
@internal_hash[:remove_commas] = true
end
|
#do_replace_this_entry(this_entry, new_filename = File.basename(this_entry).
tr(' ', replace_with_this_character?)) ⇒ Object
#
do_replace_this_entry
This method should only be called whenever this class must modify a file or a directory.
#
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
|
# File 'lib/roebe/classes/replace_space_with_underscore/replace_space_with_underscore.rb', line 794
def do_replace_this_entry(
this_entry,
new_filename = File.basename(this_entry).
tr(' ', replace_with_this_character?)
)
if be_verbose and File.exist?(new_filename)
e tomato("The target file at #{sfile(new_filename)} ")+
tomato('already exists. It will be overwritten nonetheless.')
end
append_this_to_the_modified_entries(this_entry)
unless File.basename(this_entry) == File.basename(new_filename)
if simulate_only?
e "#{rev}However, this is a simulation so we will not actually "\
"rename anything."
else if is_a_file?(this_entry)
rename_file(this_entry, new_filename) { :be_verbose }
else
FileUtils.mv(this_entry, new_filename)
end
end
end
end
|
#do_work_on_directories ⇒ Object
#
do_work_on_directories
#
387
388
389
|
# File 'lib/roebe/classes/replace_space_with_underscore/replace_space_with_underscore.rb', line 387
def do_work_on_directories
@internal_hash[:work_on_directories] = true
end
|
#get_rid_of_all_underscores? ⇒ Boolean
#
get_rid_of_all_underscores?
#
777
778
779
|
# File 'lib/roebe/classes/replace_space_with_underscore/replace_space_with_underscore.rb', line 777
def get_rid_of_all_underscores?
@internal_hash[:get_rid_of_all_underscores]
end
|
#get_rid_of_apostrophes? ⇒ Boolean
#
get_rid_of_apostrophes?
#
502
503
504
|
# File 'lib/roebe/classes/replace_space_with_underscore/replace_space_with_underscore.rb', line 502
def get_rid_of_apostrophes?
@internal_hash[:get_rid_of_apostrophes]
end
|
#get_rid_of_parens? ⇒ Boolean
531
532
533
|
# File 'lib/roebe/classes/replace_space_with_underscore/replace_space_with_underscore.rb', line 531
def get_rid_of_parens?
@internal_hash[:get_rid_of_parens]
end
|
#include_subdirectories_as_well? ⇒ Boolean
#
include_subdirectories_as_well?
#
554
555
556
|
# File 'lib/roebe/classes/replace_space_with_underscore/replace_space_with_underscore.rb', line 554
def include_subdirectories_as_well?
@internal_hash[:include_subdirectories_as_well]
end
|
#iterate_through_the_relevant_entries(token_to_use = token?,
, work_on_these_entries = work_on_these_entries?,
, be_verbose = be_verbose?
) ⇒ Object
Also known as:
run_for_real, do_process_all_given_files, batch_rename_all_files
#
iterate_through_the_relevant_entries (main tag, rename tag)
This is the powerhouse-method of this class.
#
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
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
|
# File 'lib/roebe/classes/replace_space_with_underscore/replace_space_with_underscore.rb', line 564
def iterate_through_the_relevant_entries(
token_to_use = token?,
work_on_these_entries = work_on_these_entries?,
be_verbose = be_verbose?
)
array_remove_these_strings_completely = array_remove_these_strings_completely?
shall_we_get_rid_of_parens = get_rid_of_parens?
replace_with_this_character = replace_with_this_character? seek_this_character = replace_which_character?
e
e steelblue('Now starting to do the actual work ...')
e
work_on_these_entries.each {|entry|
if shall_we_get_rid_of_parens or (
entry.include?(' ') or entry.include?('__') )
entry = entry.dup shall_we_replace_anything = entry.include?(replace_with_this_character)
if shall_we_get_rid_of_parens
shall_we_replace_anything = true
end
return unless shall_we_replace_anything
entry = entry.encode('UTF-8', invalid: :replace, undef: :replace, replace: '')
colourized = sfile(entry)
colourized = sdir(entry) if File.directory? entry
e rev+"The entry at #{colourized} #{rev}contains an "\
"#{steelblue('empty character')} #{rev}or a () / [] token."
dirname = rds(File.dirname(entry)+'/')
basename = File.basename(entry)
basename.tr!('ä¼','ü') if basename.include? 'ä¼'
basename.squeeze!('ä') if basename.include? 'ää'
basename.squeeze!('ü') if basename.include? 'üü'
basename.squeeze!('ö') if basename.include? 'öö'
basename.gsub!(/├╝/,'ü') if basename.include? '├╝'
basename.gsub!(/├╢/,'ö') if basename.include? '├╢'
basename.gsub!(/├д/,'ä') if basename.include? '├д'
basename.gsub!(/\.-\./,'') if basename.include? '-'
basename.squeeze!('_') if basename.include? '__' basename.tr!('ä¤','ä') if basename.include? 'ä¤'
basename.tr!('ö','ö') if basename.include? 'ö'
basename.tr!('ö¤','ä') if basename.include? 'ö¤'
basename.tr!('Ã?','Ü') if basename.include? 'Ã?'
basename.tr!('ö?','Ü') if basename.include? 'ö?'
if basename.include?('_-_')
basename = basename.sub(/_-_/, replacement_char?)
end
basename.sub!(/^ä?/,'Ü') if basename.start_with? 'ä?'
basename.tr!('ä¼','ü') if basename.include? 'ä¼'
if basename.include? '_&_'
basename.gsub!(/_&_/,'_and_')
elsif basename.include? '&'
basename.gsub!(/&/,'_and_')
end
if basename.include?("'") and get_rid_of_apostrophes?
basename.delete!("'")
end
basename.tr!("ö\x9",'Ü') if basename.include? "ö\x9"
basename.delete! '{' basename.delete! '}' basename.delete_suffix!('.part') if basename.include? '.part'
if basename.end_with?('_') basename.gsub!(/_{1,15}$/, '') end
if shall_we_get_rid_of_parens
case shall_we_get_rid_of_parens
when :get_rid_only_of_squared_parens
basename.delete!('[]') else
basename.delete!('()[]') end
end
basename.tr!('Ã?','ä')
basename.tr!('ä','ä') if basename.include? 'ä'
if basename.include?('_') and get_rid_of_all_underscores?
basename.tr!('_','')
end
if basename.include?(',') and remove_commas?
basename.delete!(',')
end
unless array_remove_these_strings_completely.empty? array_remove_these_strings_completely.each {|remove_this_substring|
if basename.include? remove_this_substring
basename.gsub!(/#{remove_this_substring}/,'')
end
}
end
begin
new_filename = dirname+
basename.
tr(seek_this_character, replace_with_this_character)
rescue ArgumentError => error
e
pp error
e
e rev+"A problem was encountered for the entry at: #{sfile(entry)}"
end
if be_verbose
e "#{rev}Renaming #{sfile(entry)} #{rev}towards "\
"#{sfile(new_filename)}#{rev}."
end
e rev+'This will now be replaced via a '+
steelblue(token_to_use)+
rev+', to the new name '+
sfile(new_filename)+
rev+
'.'
do_replace_this_entry(entry, new_filename)
else
if File.exist?(entry)
e rev+"The entry at #{::Colours.sfile_or_sdir(entry)}"
e "#{rev}does not include the character that should be replaced - "\
"which is #{steelblue(seek_this_character)}."
else
no_file_exists_at(entry)
end
end
}
end
|
#
The menu() interface will receive the arguments given on the commandline to this class. This will usually be ARGV, so hence an Array.
#
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
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
334
335
336
337
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
|
# File 'lib/roebe/classes/replace_space_with_underscore/replace_space_with_underscore.rb', line 258
def (
i = commandline_arguments?
)
if i.is_a? Array
i.each {|entry| (entry) }
else
i = i.encode('UTF-8', invalid: :replace, undef: :replace, replace: '')
case i when /^-?-?no(-|_)?squared(-|_)?parens$/,
/^-?-?remove(-|_)?eckige(-|_)?klammern$/
@internal_hash[:get_rid_of_parens] = :get_rid_only_of_squared_parens
when /^-?-?no(-|_)?parens$/i,
/^-?-?remove(-|_)?runde(-|_)?klammern$/
e 'We will also get rid of "(" and ")".'
do_get_rid_of_parens
when /^-?-?everything$/i,
/^-?-?perfect$/i,
/^-?-?super$/i do_remove_commas
do_get_rid_of_parens
when /^-?-?dirs?$/i, /^-?-?all$/i,
/^-?-?also(-|_)?dirs$/,
/^-?-?also(-|_)?directories$/,
/^-?-?directories$/i
do_get_rid_of_parens
do_work_on_directories
when /^-?-?only(-|_)?dirs$/,
/^-?-?only(-|_)?directories$/,
/^-?-?directories$/
do_work_on_directories
do_not_work_on_files
when /^-?-?traverse$/i
@internal_hash[:include_subdirectories_as_well] = true
when /^-?-?no(-|_)?underscores\??$/i
get_rid_of_all_underscores
when /^-?-?no(-|_)?commas$/,
/^-?-?remove(-|_)?commas$/
do_remove_commas
when /-?-?no(-|_)?apostrophe?s?/,
/-?-?remove(-|_)?apostrophe?s?/
@internal_hash[:get_rid_of_apostrophes] = true
when /^-?-?help$/i,
/^-?-?show(-|_| )?help$/i
show_help
exit
else
if i and i.start_with?('--')
e "The flag #{steelblue(i)} was not registered in menu()."
elsif File.directory?(i) and work_on_directories?
append_this_entry(i)
elsif !File.exist?(i)
e "We will also remove the substring `#{sfancy(i)}`."
append_to_the_array_remove_these_strings_completely(i)
end
end
end
end
|
#notify_the_user_that_we_have_finished? ⇒ Boolean
#
notify_the_user_that_we_have_finished?
#
495
496
497
|
# File 'lib/roebe/classes/replace_space_with_underscore/replace_space_with_underscore.rb', line 495
def notify_the_user_that_we_have_finished?
true
end
|
#obtain_all_relevant_entries ⇒ Object
#
obtain_all_relevant_entries
#
538
539
540
541
542
543
544
545
546
547
548
549
|
# File 'lib/roebe/classes/replace_space_with_underscore/replace_space_with_underscore.rb', line 538
def obtain_all_relevant_entries
from_where = '*'.dup
from_where << '*/**' if include_subdirectories_as_well?
_ = Dir[from_where]
if work_on_files?
_.select! {|entry| is_a_file?(entry) }
end
if work_on_directories?
_.select! {|entry| is_a_directory?(entry) }
end
append_work_on_these_entries(_)
end
|
#remove_commas? ⇒ Boolean
168
169
170
|
# File 'lib/roebe/classes/replace_space_with_underscore/replace_space_with_underscore.rb', line 168
def remove_commas?
@internal_hash[:remove_commas]
end
|
#replace_which_character? ⇒ Boolean
#
replace_which_character?
#
175
176
177
|
# File 'lib/roebe/classes/replace_space_with_underscore/replace_space_with_underscore.rb', line 175
def replace_which_character?
@internal_hash[:replace_which_character]
end
|
#replace_with_this_character? ⇒ Boolean
Also known as:
replacement_char?, replace_with_which_character?, token?
#
replace_with_this_character?
This method will return the replacement-character that is to be used. Normally this will default to ‘_’, as that character seems to cause the least issues on the commandline.
#
486
487
488
|
# File 'lib/roebe/classes/replace_space_with_underscore/replace_space_with_underscore.rb', line 486
def replace_with_this_character?
@internal_hash[:replace_with_this_character]
end
|
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
|
# File 'lib/roebe/classes/replace_space_with_underscore/replace_space_with_underscore.rb', line 85
def reset
super()
infer_the_namespace
be_verbose opnn { :no_trailing }; e; e
set_default_token set_replace_which_character(:default)
@internal_hash[:work_on_files] = true
@internal_hash[:work_on_directories] = WORK_ON_DIRECTORIES_AS_WELL
@internal_hash[:work_on_these_entries] = []
@internal_hash[:simulate_only] = false
@internal_hash[:array_remove_these_strings_completely] = []
@internal_hash[:include_subdirectories_as_well] = false
@internal_hash[:get_rid_of_parens] = false
@internal_hash[:get_rid_of_all_underscores] = false
@internal_hash[:array_these_entries_were_modified] = []
@internal_hash[:remove_commas] = GET_RID_OF_COMMA
@internal_hash[:get_rid_of_apostrophes] = false
end
|
825
826
827
828
829
830
831
832
833
834
835
|
# File 'lib/roebe/classes/replace_space_with_underscore/replace_space_with_underscore.rb', line 825
def run
obtain_all_relevant_entries if work_on_these_entries?.empty?
e rev+'Please provide at the least one argument to '\
'this class - usually either a file, or a directory.'
else
iterate_through_the_relevant_entries
consider_notifying_the_user_that_we_are_done_now
end
end
|
#set_default_token ⇒ Object
408
409
410
|
# File 'lib/roebe/classes/replace_space_with_underscore/replace_space_with_underscore.rb', line 408
def set_default_token
set_token(REPLACE_WITH_THIS_CHARACTER)
end
|
#set_replace_which_character(i = :default) ⇒ Object
Also known as:
replace_this_character=, replace_which_character=
#
set_replace_which_character
#
509
510
511
512
513
514
515
516
517
518
|
# File 'lib/roebe/classes/replace_space_with_underscore/replace_space_with_underscore.rb', line 509
def set_replace_which_character(i = :default)
case i
when :default
i = REPLACE_WHICH_CHARACTER
end
@internal_hash[:replace_which_character] = i
end
|
#set_replace_with_this_character(i = REPLACE_WITH_THIS_CHARACTER, be_verbose = be_verbose?
) ⇒ Object
Also known as:
set_token
#
set_replace_with_this_character
#
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
|
# File 'lib/roebe/classes/replace_space_with_underscore/replace_space_with_underscore.rb', line 415
def set_replace_with_this_character(
i = REPLACE_WITH_THIS_CHARACTER,
be_verbose = be_verbose?
)
case i.to_s when 'default'
i = REPLACE_WITH_THIS_CHARACTER
when 'NONE'
i = ''
end
if i.include? '--' i = REPLACE_WITH_THIS_CHARACTER
end
if be_verbose
e rev+'Setting to the token `'+sfancy(i.to_s)+rev+'` now. '+
'This is the character used by this'
e "#{rev}class to replace the (default) \" \" character."
end
@internal_hash[:replace_with_this_character] = i
end
|
#set_work_on_these_entries(i) ⇒ Object
Also known as:
set_work_on_these_files, set_file, set_files
#
set_work_on_these_entries
This class works on “entries”, which basically means files and directories. Normally the class works on files, though - this is the default behaviour.
This method should be used whenever this class should designate which files (and directories) are to be modified.
Note that some convenience-aliases exist for this method, such as .set_file().
#
463
464
465
466
|
# File 'lib/roebe/classes/replace_space_with_underscore/replace_space_with_underscore.rb', line 463
def set_work_on_these_entries(i)
i = [i].flatten.compact @internal_hash[:work_on_these_entries] = i
end
|
#show_help ⇒ Object
#
show_help (help tag)
To invoke this method, do:
rblanks --help
#
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
|
# File 'lib/roebe/classes/replace_space_with_underscore/replace_space_with_underscore.rb', line 231
def show_help
e
e "#{rev}The documented help options for "\
"#{steelblue('class ReplaceSpaceWithUnderscore')} are:"
e
result = <<EOF
--everything # apply all available options
--traverse # traverse through all directories in this directory
--dirs # also work on directories
--only-dirs # work on directories only
--no-parens # get rid of "(" and ")" and also "[" and "]" parens in a filename
--remove-runde-klammern # remove all '()'; similar to --no-parens
--no-squared-parens # get rid of "[" and "]" parens in a filename
--no-commas # remove all commas aka "," tokens
--no-underscores # remove all underscores aka "_" tokens
--no-apostroph # remove all apostrophs aka "'" tokens
EOF
result.split("\n").each {|entry| entry }; e
end
|
#simulate_only? ⇒ Boolean
380
381
382
|
# File 'lib/roebe/classes/replace_space_with_underscore/replace_space_with_underscore.rb', line 380
def simulate_only?
@internal_hash[:simulate_only]
end
|
#work_on_directories? ⇒ Boolean
446
447
448
|
# File 'lib/roebe/classes/replace_space_with_underscore/replace_space_with_underscore.rb', line 446
def work_on_directories?
@internal_hash[:work_on_directories]
end
|
#work_on_files? ⇒ Boolean
439
440
441
|
# File 'lib/roebe/classes/replace_space_with_underscore/replace_space_with_underscore.rb', line 439
def work_on_files?
@internal_hash[:work_on_files]
end
|
#work_on_these_entries? ⇒ Boolean
Also known as:
work_on_these_files?, files?, obtain_the_files
#
work_on_these_entries?
This method will return on which files and directories this class will work - that is, which files and directories will be renamed effectively.
#
371
372
373
|
# File 'lib/roebe/classes/replace_space_with_underscore/replace_space_with_underscore.rb', line 371
def work_on_these_entries?
@internal_hash[:work_on_these_entries]
end
|