andela-amagana
11/23/2017 - 12:22 PM

Open closed principle pass

# Here we pass the file format parser as a paremeter
# This design allows for extension by means of adding other
# classes that support other formats, doing this
# without having to modify class, UsageFileParser
class UsageFileParser
  def initialize(client, parser)
    @client = client
    @parser = parser
  end
  
  def parse(usage_file)
    @parser.parse(usage_file)
    @client.last_parse = Time.now
    @client.save!
  end
end

class XmlParser
  def parse(usage_file)
    # parse_xml
  end
end

class CsvParser
  def parse(usage_file)
    # parse_csv
  end
end