-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview_helper.rb
37 lines (31 loc) · 972 Bytes
/
view_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class PaymentViewHelper < ViewHelper
def preview(payment)
content = h.content_tag(:span, class: "col-md-1") do
payment_icon(payment)
end
klasses = "pp-overview row #{"credit-card" if payment.type == "credit_card"}"
h.content_tag(:div, class: klasses) do
content << payment_name(payment)
end
end
private
def payment_icon(payment)
case payment.type
when "credit_card"
h.concat(h.content_tag(:span, payment.card_type, class: "card-type"))
h.concat(h.credit_card_icon(payment.card_type))
when "bank_account"
h.concat(h.icon('bank'))
h.concat(h.content_tag(:span, payment.bank_name.truncate(1), class: "card-type"))
end
end
def payment_name(payment)
text = case payment.type
when "credit_card"
payment.masked_card_number
when "bank_account"
payment.bank_name
end
h.content_tag(:span, text, class: "col-md-11")
end
end