Class: Lease::BidSerializer
Class Method Summary
collapse
format_date, locale_date_format, next_hour
currency_attribute_name, currency_for_label, currency_symbol, num_to_cur
#collection_for_select, #collection_name_by_id
opts, serialize
Class Method Details
.account_id(bid) ⇒ Object
34
35
36
|
# File 'app/serializers/lease/bid_serializer.rb', line 34
def account_id(bid)
{ account_id: bid.account_id }
end
|
.available_attributes ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'app/serializers/lease/bid_serializer.rb', line 10
def available_attributes
i[
id
account_id
inquiry_id
boat_id
boat
price
currency
state
from
to
period
duration
human_price
human_price_vat_incl
].freeze
end
|
.boat(bid) ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
|
# File 'app/serializers/lease/bid_serializer.rb', line 46
def boat(bid)
boat = bid.boat
{
boat: {
id: boat.id,
img_url: (boat.boat_photo.picture.url(:thumb) if boat.boat_photo.present?),
name: boat.name,
type: (boat.boat_type.name rescue nil)
}
}
end
|
.boat_id(bid) ⇒ Object
42
43
44
|
# File 'app/serializers/lease/bid_serializer.rb', line 42
def boat_id(bid)
{ boat_id: bid.boat_id }
end
|
112
113
114
|
# File 'app/serializers/lease/bid_serializer.rb', line 112
def (bid)
{ comments: bid. }
end
|
.currency(bid) ⇒ Object
62
63
64
|
# File 'app/serializers/lease/bid_serializer.rb', line 62
def currency(bid)
{ currency: bid.currency }
end
|
.duration(bid) ⇒ Object
88
89
90
91
92
93
94
95
96
97
98
|
# File 'app/serializers/lease/bid_serializer.rb', line 88
def duration(bid)
distance = (bid.to - bid.from).to_i / 24 / 60 / 60
distance = distance.zero? ? 1 : distance
uom = I18n.t('activerecord.labels.lease/bid.day', count: distance)
{
duration: {
distance: distance,
uom: uom
}
}
end
|
.from(bid) ⇒ Object
100
101
102
|
# File 'app/serializers/lease/bid_serializer.rb', line 100
def from(bid)
{ from: format_date(bid.from, @opts[:locale]) }
end
|
.human_price(bid) ⇒ Object
66
67
68
69
70
71
72
|
# File 'app/serializers/lease/bid_serializer.rb', line 66
def human_price(bid)
val = nil
if bid.price.present? && bid.currency.present?
val = num_to_cur(bid.price, bid.currency, @opts[:locale])
end
{ human_price: val }
end
|
.human_price_vat_incl(bid) ⇒ Object
74
75
76
77
78
79
80
81
82
|
# File 'app/serializers/lease/bid_serializer.rb', line 74
def human_price_vat_incl(bid)
val = nil
if bid.price.present? && bid.currency.present?
val = bid.price / 100.0 * (100 + bid.vat)
val = num_to_cur(val.to_i, bid.currency, @opts[:locale])
end
{ human_price_vat_incl: val }
end
|
.id(bid) ⇒ Object
30
31
32
|
# File 'app/serializers/lease/bid_serializer.rb', line 30
def id(bid)
{ id: bid.id }
end
|
.inquiry_id(bid) ⇒ Object
38
39
40
|
# File 'app/serializers/lease/bid_serializer.rb', line 38
def inquiry_id(bid)
{ inquiry_id: bid.inquiry_id }
end
|
.period(bid) ⇒ Object
84
85
86
|
# File 'app/serializers/lease/bid_serializer.rb', line 84
def period(bid)
{ period: '%s - %s' % [from(bid)[:from], to(bid)[:to]] }
end
|
.price(bid) ⇒ Object
58
59
60
|
# File 'app/serializers/lease/bid_serializer.rb', line 58
def price(bid)
{ price: bid.price }
end
|
.state(bid) ⇒ Object
108
109
110
|
# File 'app/serializers/lease/bid_serializer.rb', line 108
def state(bid)
{ state: bid.state }
end
|
.to(bid) ⇒ Object
104
105
106
|
# File 'app/serializers/lease/bid_serializer.rb', line 104
def to(bid)
{ to: format_date(bid.to, @opts[:locale]) }
end
|