require_relative 'parse'

module Parsefiles
  class FileOps

    include Parse

    attr_accessor :file,:pattern

    def initialize(file,pattern)
      @file = file
      @pattern = pattern
    end

    def get_file_type
      File.extname(@file).gsub!(/\./,'')
    end

    def parse_file
      method_name = "parse_#{get_file_type}"
      self.send method_name.to_sym
    end

    def match_line(line)
      line = encode_string(line)
      p line if line.match(@pattern)
    end

    def encode_string(input)
      encode_it(input)
    end

    private

    def encode_it(input)
      input.force_encoding('UTF-8').encode('UTF-16', :invalid => :replace, :replace => '').encode('UTF-8')
    end

  end

end
