Class: AhoyCaptain::ApplicationDecorator

Inherits:
Object
  • Object
show all
Defined in:
app/decorators/ahoy_captain/application_decorator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, context) ⇒ ApplicationDecorator

Returns a new instance of ApplicationDecorator.



28
29
30
31
# File 'app/decorators/ahoy_captain/application_decorator.rb', line 28

def initialize(object, context)
  @object = object
  @context = context
end

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object.



5
6
7
# File 'app/decorators/ahoy_captain/application_decorator.rb', line 5

def object
  @object
end

Class Method Details

.csv_map(params = {}) ⇒ Object

Raises:

  • (NotImplementedError)


23
24
25
# File 'app/decorators/ahoy_captain/application_decorator.rb', line 23

def self.csv_map(params = {})
  raise NotImplementedError
end

.to_csv(collection, context) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/decorators/ahoy_captain/application_decorator.rb', line 7

def self.to_csv(collection, context)
  rows = collection.map { |row| new(row, context) }
  CSV.generate do |csv|
    csv << csv_map(context.params).keys

    rows.each do |row|
      items = []
      csv_map.values.each do |attr|
        items << row.send(attr)
      end

      csv << items
    end
  end
end