Module: Sed::Commander
Instance Method Summary collapse
- #argv(input_file_path, expression, replacement, opts = {}) ⇒ Object
- #extended_regex_option ⇒ Object
- #inplace_option ⇒ Object
- #replace(input_file_path, expression, replacement, opts = {}) ⇒ Object
Instance Method Details
#argv(input_file_path, expression, replacement, opts = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/sed/commander.rb', line 11 def argv(input_file_path, expression, replacement, opts = {}) result = [] if opts[:output].nil? result << Sed::Commander.inplace_option end if opts[:extended_regex] result << Sed::Commander.extended_regex_option end result << "'s/#{expression}/#{replacement}/g'" result << "'#{input_file_path}'" if opts[:output] result << "> '#{opts[:output]}'" end result.join(' ') end |
#extended_regex_option ⇒ Object
37 38 39 40 |
# File 'lib/sed/commander.rb', line 37 def extended_regex_option return "-E" if Sed::Util.osx? return "-r" if Sed::Util.gnu? end |
#inplace_option ⇒ Object
32 33 34 35 |
# File 'lib/sed/commander.rb', line 32 def inplace_option return "-i ''" if Sed::Util.osx? return "-i" if Sed::Util.gnu? end |
#replace(input_file_path, expression, replacement, opts = {}) ⇒ Object
6 7 8 9 |
# File 'lib/sed/commander.rb', line 6 def replace(input_file_path, expression, replacement, opts = {}) command = "sed #{argv(input_file_path, expression, replacement, opts)}" result = Kernel.system command end |