Class: Spree::CSV::GiftCardPresenter

Inherits:
Object
  • Object
show all
Includes:
MetafieldsHelper
Defined in:
app/presenters/spree/csv/gift_card_presenter.rb

Constant Summary collapse

HEADERS =
[
  'Code',
  'Amount',
  'Amount Used',
  'Amount Remaining',
  'Currency',
  'Status',
  'Expires At',
  'Customer Email',
  'Customer First Name',
  'Customer Last Name',
  'Created At',
  'Updated At'
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gift_card) ⇒ GiftCardPresenter

Returns a new instance of GiftCardPresenter.



21
22
23
# File 'app/presenters/spree/csv/gift_card_presenter.rb', line 21

def initialize(gift_card)
  @gift_card = gift_card
end

Instance Attribute Details

#gift_cardObject

Returns the value of attribute gift_card.



25
26
27
# File 'app/presenters/spree/csv/gift_card_presenter.rb', line 25

def gift_card
  @gift_card
end

Instance Method Details

#callObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/presenters/spree/csv/gift_card_presenter.rb', line 27

def call
  csv = [
    gift_card.display_code,
    gift_card.display_amount,
    gift_card.display_amount_used,
    gift_card.display_amount_remaining,
    gift_card.currency,
    gift_card.display_state,
    gift_card.expires_at&.strftime('%Y-%m-%d'),
    gift_card.user&.email,
    gift_card.user&.first_name,
    gift_card.user&.last_name,
    gift_card.created_at&.strftime('%Y-%m-%d %H:%M:%S'),
    gift_card.updated_at&.strftime('%Y-%m-%d %H:%M:%S')
  ]

  csv += metafields_for_csv(gift_card)

  csv
end