Class: AhoyCaptain::Export

Inherits:
Object
  • Object
show all
Defined in:
app/models/ahoy_captain/export.rb

Instance Method Summary collapse

Constructor Details

#initialize(params, context) ⇒ Export

Returns a new instance of Export.



3
4
5
6
7
# File 'app/models/ahoy_captain/export.rb', line 3

def initialize(params, context)
  @params = params
  @context = context
  @files = {}
end

Instance Method Details

#buildObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/models/ahoy_captain/export.rb', line 9

def build
  @files["browsers.csv"] = to_csv(DeviceQuery.call(merged_params(devices_type: "browser")), DeviceDecorator)
  @files["cities.csv"] = to_csv(CityQuery.call(merged_params), CityDecorator)
  @files["countries.csv"] = to_csv(CountryQuery.call(merged_params), CountryDecorator)
  @files["devices.csv"] = to_csv(DeviceQuery.call(merged_params(devices_type: :device_type)), DeviceDecorator)
  @files["entry_pages.csv"] = to_csv(EntryPagesQuery.call(merged_params), EntryPageDecorator)
  @files["exit_pages.csv"] = to_csv(ExitPagesQuery.call(merged_params), ExitPageDecorator)
  @files["operating_systems.csv"] = to_csv(DeviceQuery.call(merged_params(devices_type: "os")), DeviceDecorator)
  @files["top_pages.csv"] = to_csv(TopPageQuery.call(merged_params), TopPageDecorator)
  @files["regions.csv"] = to_csv(RegionQuery.call(merged_params), RegionDecorator)
  @files["sources.csv"] = to_csv(SourceQuery.call(merged_params), SourceDecorator)
  ["campaign", "content", "medium", "source", "term"].each do |utm|
    @files["utm_#{utm.pluralize}.csv"] = to_csv(CampaignQuery.call(merged_params(campaigns_type: "utm_#{utm}")), CampaignDecorator)
  end
  self
end

#to_zipObject



26
27
28
29
30
31
32
33
34
35
36
# File 'app/models/ahoy_captain/export.rb', line 26

def to_zip
  zip_stream = Zip::OutputStream.write_buffer do |zip|
    @files.each do |filename, csv|
      zip.put_next_entry(filename)
      zip.write(csv)
    end
  end

  zip_stream.rewind
  zip_stream
end