Class: LicenseScout::Exporter

Inherits:
Object
  • Object
show all
Defined in:
lib/license_scout/exporter.rb,
lib/license_scout/exporter/csv.rb

Defined Under Namespace

Classes: CSV

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json_file, export_format) ⇒ Exporter

Returns a new instance of Exporter.


27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/license_scout/exporter.rb', line 27

def initialize(json_file, export_format)
  @json_file = json_file
  @export_format = export_format

  @exporter = case export_format
              when "csv"
                LicenseScout::Exporter::CSV.new(json_file)
              else
                # We shouldn't ever hit this, because the CLI filters out unsupported formats. But just in case...
                raise LicenseScout::Exceptions::UnsupportedExporter.new("'#{export_format}' is not a supported format. Please use one of the following: #{supported_formats.join(", ")}")
              end
end

Instance Attribute Details

#export_formatObject (readonly)

Returns the value of attribute export_format.


24
25
26
# File 'lib/license_scout/exporter.rb', line 24

def export_format
  @export_format
end

#exporterObject (readonly)

Returns the value of attribute exporter.


25
26
27
# File 'lib/license_scout/exporter.rb', line 25

def exporter
  @exporter
end

#json_fileObject (readonly)

Returns the value of attribute json_file.


23
24
25
# File 'lib/license_scout/exporter.rb', line 23

def json_file
  @json_file
end

Class Method Details

.supported_formatsObject


40
41
42
43
44
# File 'lib/license_scout/exporter.rb', line 40

def self.supported_formats
  [
    "csv",
  ]
end

Instance Method Details

#exportObject


46
47
48
49
# File 'lib/license_scout/exporter.rb', line 46

def export
  LicenseScout::Log.info("[exporter] Exporting #{json_file} to '#{export_format}'")
  exporter.export
end