class RBT::SedWrapper
Constants
- DEFAULT_SED_COMMAND
#¶ ↑
DEFAULT_SED_COMMAND
¶ ↑#¶ ↑
- REPORT_INPUT_COMMAND
#¶ ↑
REPORT_INPUT_COMMAND
¶ ↑#¶ ↑
- SED_COMMAND2
#¶ ↑
SED_COMMAND2
¶ ↑#¶ ↑
- SED_COMMAND3
#¶ ↑
SED_COMMAND3
¶ ↑#¶ ↑
Public Class Methods
[](i = '')
click to toggle source
Public Instance Methods
batch_modify_the_files()
click to toggle source
#¶ ↑
batch_modify_the_files
¶ ↑
#¶ ↑
# File lib/rbt/misc/sed_wrapper.rb, line 166 def batch_modify_the_files what = ''.dup # String to store. @input.delete!("'") if @input.start_with?('s/') @input[0,1] = '' end splitted = @input.split('/').reject(&:empty?) # @input must obviously have a '/' character. replace_this = splitted.first with_that = splitted[1] case with_that when 'd' # ===================================================================== # # This will be assumed to mean 'delete' but only in certain cases. # ===================================================================== # if @input.count('/') < 3 with_that = '' # Chop it off in this case. end end work_on_these_files.each {|this_file| opne 'Working on the file `'+sfile(this_file)+'`.' try_to_read_in_this_file(this_file) # <- This sets @dataset again. if @dataset @dataset.each {|line| if line.include? replace_this line.gsub!(/#{replace_this}/, with_that) end # ================================================================= # # Do the substitute-action here. # ================================================================= # what << line } opne 'Storing into the file `'+sfile(this_file)+'` now. '\ '(Substitution on: '+sfancy(replace_this)+'; '\ 'Replacement on: '+sfancy(with_that)+')' save_what_into(what, this_file) what = '' # Reset again. end } end
determine_on_which_files_to_work()
click to toggle source
#¶ ↑
determine_on_which_files_to_work
¶ ↑
#¶ ↑
# File lib/rbt/misc/sed_wrapper.rb, line 118 def determine_on_which_files_to_work _ = @input # Grab a copy of the remaining input first. if _.include? "'" rindex = _.rindex "'" string_for_files = _[(rindex+1)..-1] set_work_on_these_files string_for_files.strip.split(' ').map(&:chomp) @input = _[0..rindex] end end
input?()
click to toggle source
reset()
click to toggle source
#¶ ↑
reset (reset tag)¶ ↑
#¶ ↑
Calls superclass method
RBT::Base#reset
# File lib/rbt/misc/sed_wrapper.rb, line 86 def reset super() infer_the_namespace # ======================================================================= # # === :work_on_these_files # ======================================================================= # @internal_hash[:work_on_these_files] = [] # ======================================================================= # # === @dataset # ======================================================================= # @dataset = nil end
run()
click to toggle source
sanitize_input()
click to toggle source
set_input( i = DEFAULT_SED_COMMAND )
click to toggle source
#¶ ↑
set_input
¶ ↑
#¶ ↑
# File lib/rbt/misc/sed_wrapper.rb, line 64 def set_input( i = DEFAULT_SED_COMMAND ) i = i.first if i.is_a? Array i = DEFAULT_SED_COMMAND if i.nil? i = i.to_s.dup case i # case tag when 'sed2','s2','2' i = SED_COMMAND2 when 'sed3','s3','3' i = SED_COMMAND3 end @input = i if REPORT_INPUT_COMMAND opne "The sed command used will be: #{sfancy(i)}" end sanitize_input end
set_work_on_these_files(i)
click to toggle source
#¶ ↑
set_work_on_these_files
¶ ↑
It is better to store the absolute path towards the file at hand.
#¶ ↑
# File lib/rbt/misc/sed_wrapper.rb, line 133 def set_work_on_these_files(i) unless i.is_a? Array i = [i] end if i.is_a? Array i.map! {|entry| File.absolute_path(entry) } end @internal_hash[:work_on_these_files] = i end
try_to_read_in_this_file(i = target_file?)
click to toggle source