Class: Anoubis::Export

Inherits:
Object
  • Object
show all
Defined in:
app/controllers/anoubis/export.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Export

Returns a new instance of Export.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/anoubis/export.rb', line 8

def initialize(options = {})
  self.data = []
  self.title = []
  options[:format] = 'xls' if !options.key? :format
  self.format = options[:format]
  self.fields = if options.key?(:fields) then options[:fields] else nil end
  if self.fields
    self.fields.each do |field|
      self.title.push field[:title]
    end
  end
end

Instance Method Details

#add(data) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/anoubis/export.rb', line 21

def add (data)
  data.each do |dat|
    new_data = []
    self.fields.each do |field|
      if dat.key? field[:id].to_sym
        new_data.push dat[field[:id].to_sym]
      else
        new_data.push ''
      end
    end
    #new_data = dat.except :actions, :sys_title
    self.data.push(new_data)
  end
end

#to_hObject



36
37
38
39
40
41
42
43
# File 'app/controllers/anoubis/export.rb', line 36

def to_h
  {
      data: self.data,
      title: self.title,
      fields: self.fields,
      format: self.format
  }
end