Class: MaskSQL::Converter
- Inherits:
-
Object
- Object
- MaskSQL::Converter
- Defined in:
- lib/mask_sql/converter.rb
Instance Method Summary collapse
-
#initialize(options) ⇒ Converter
constructor
A new instance of Converter.
- #mask(encoding = nil) ⇒ Object
Constructor Details
#initialize(options) ⇒ Converter
Returns a new instance of Converter.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/mask_sql/converter.rb', line 6 def initialize() @options = config = YAML.load_file([:config]) @mark = config['mark'] @targets = config['targets'] if [:insert].nil? && [:replace].nil? && [:copy].nil? @options[:insert] = true @options[:replace] = true @options[:copy] = true end @matched_copy = {} end |
Instance Method Details
#mask(encoding = nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/mask_sql/converter.rb', line 22 def mask(encoding = nil) encoding ||= NKF.guess(File.read(@options[:in])).name File.open(@options[:out], "w:#{encoding}") do |out_file| File.open(@options[:in], "r:#{encoding}") do |in_file| in_file.each_line do |line| if @matched_copy.empty? @counters = [] write_line(line, out_file) else write_copy_line(line, out_file) end end end end rescue Encoding::UndefinedConversionError => e raise Encoding::UndefinedConversionError, e. if encoding == Encoding::UTF_8.name mask(Encoding::UTF_8.name) end |