Class: MaskSQL::Converter

Inherits:
Object
  • Object
show all
Defined in:
lib/mask_sql/converter.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Converter

Returns a new instance of Converter.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/mask_sql/converter.rb', line 7

def initialize(options)
  @options = options

  config = YAML.load_file(options[:config])
  @mark = config['mark']
  @targets = config['targets']

  if options[:insert].nil? && options[:replace].nil? && options[:copy].nil?
    @options[:insert] = true
    @options[:replace] = true
    @options[:copy] = true
  end

  @matched_copy = {}
end

Instance Method Details

#maskObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/mask_sql/converter.rb', line 23

def mask
  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|
        @matched_copy.empty? ? write_line(line, out_file) : write_copy_line(line, out_file)
      end
    end
  end
end