module AdjustN
Copyright (C) 2012 Kenichi Kamiya
Constants
- VERSION
Public Class Methods
run(after_code, *pathnames)
click to toggle source
@param [Symbol, String] after_code @return [void]
# File lib/adjustn/singleton_class.rb, line 8 def run(after_code, *pathnames) raise ArgumentError unless pathnames.length >= 1 before, after = *pair_for(after_code) pathnames.each do |pathname| source = File.binread(pathname) if output = gsub_for!(source, before, after) File.open(pathname, 'wb') do |f| f << output end else $stderr.puts %Q!Already adjuted the file "#{pathname}"! end end end
Private Class Methods
gsub_for!(source, before, after)
click to toggle source
@return [String, nil] @note for easy testing
# File lib/adjustn/singleton_class.rb, line 36 def gsub_for!(source, before, after) source.gsub!(before) { after } end
pair_for(want)
click to toggle source
@return [NewlineChar::Pair]
# File lib/adjustn/singleton_class.rb, line 29 def pair_for(want) want = NewlineChar.autonym(want) NewlineChar::PAIRS.fetch(want) end