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
38
39
40
|
# File 'app/serializers/lease/bid_serializer.rb', line 38
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
29
30
31
32
|
# File 'app/serializers/lease/bid_serializer.rb', line 10
def available_attributes
i[
id
account_id
inquiry_id
boat_id
boat
price
price_percent
cancellation_type
human_payment_prices
currency
state
from
to
period
duration
human_price
human_price_vat_incl
].freeze
end
|
.boat(bid) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'app/serializers/lease/bid_serializer.rb', line 50
def boat(bid)
boat = bid.boat
boat_serialized = BoatSerializer.serialize boat, attributes: i[
name
boat_length
guests_total
guest_cabins
crew_total
boat_stars
builder
built_year
]
boat_serialized[:boat_length][:value] = boat_serialized[:boat_length][:value].to_i
{
boat: {
img_url: (boat.boat_photo.picture.url(:thumb) if boat.boat_photo.present?),
gallery_img_url: (boat.boat_photo.picture.url(:gallery) if boat.boat_photo.present?),
type: (boat.boat_type.name rescue nil),
**boat_serialized
}
}
end
|
.boat_id(bid) ⇒ Object
46
47
48
|
# File 'app/serializers/lease/bid_serializer.rb', line 46
def boat_id(bid)
{ boat_id: bid.boat_id }
end
|
.cancellation_type(bid) ⇒ Object
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'app/serializers/lease/bid_serializer.rb', line 82
def cancellation_type(bid)
return { cancellation_type: nil } if bid.cancellation_type.nil?
ct = ::Dicts::Lease::OfferCancelation.find bid.cancellation_type
{ cancellation_type: {
id: ct.id,
title: I18n.t('lease.offer_cancelation.%s.title' % ct.index),
short: I18n.t('lease.offer_cancelation.%s.short' % ct.index),
full_html: I18n.t('lease.offer_cancelation.%s.full_html' % ct.index)
}
}
end
|
158
159
160
|
# File 'app/serializers/lease/bid_serializer.rb', line 158
def (bid)
{ comments: bid. }
end
|
.currency(bid) ⇒ Object
108
109
110
|
# File 'app/serializers/lease/bid_serializer.rb', line 108
def currency(bid)
{ currency: bid.currency }
end
|
.duration(bid) ⇒ Object
134
135
136
137
138
139
140
141
142
143
144
|
# File 'app/serializers/lease/bid_serializer.rb', line 134
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
|
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
# File 'app/serializers/lease/bid_serializer.rb', line 162
def (bid)
= i[
].map do |attr|
[attr, bid.send(attr)]
end.to_h.select do |_, value|
!value.nil?
end.map do |a,v|
if a == :extra_apa
[a, '%s %' % v ]
else
[a, num_to_cur(v,bid.currency, @opts[:locale])]
end
end.to_h
{ extra: }
end
|
.from(bid) ⇒ Object
146
147
148
|
# File 'app/serializers/lease/bid_serializer.rb', line 146
def from(bid)
{ from: format_date(bid.from, @opts[:locale]) }
end
|
.human_payment_prices(bid) ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
|
# File 'app/serializers/lease/bid_serializer.rb', line 96
def human_payment_prices(bid)
if bid.price.present? && bid.price_percent.present?
first_price = bid.price * bid.price_percent / 100
{
human_payment_prices: {
first_payment: num_to_cur(first_price, bid.currency, @opts[:locale]),
second_payment: num_to_cur((bid.price - first_price), bid.currency, @opts[:locale])
}
}
end
end
|
.human_price(bid) ⇒ Object
112
113
114
115
116
117
118
|
# File 'app/serializers/lease/bid_serializer.rb', line 112
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
120
121
122
123
124
125
126
127
128
|
# File 'app/serializers/lease/bid_serializer.rb', line 120
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
34
35
36
|
# File 'app/serializers/lease/bid_serializer.rb', line 34
def id(bid)
{ id: bid.id }
end
|
.inquiry_id(bid) ⇒ Object
42
43
44
|
# File 'app/serializers/lease/bid_serializer.rb', line 42
def inquiry_id(bid)
{ inquiry_id: bid.inquiry_id }
end
|
.period(bid) ⇒ Object
130
131
132
|
# File 'app/serializers/lease/bid_serializer.rb', line 130
def period(bid)
{ period: '%s - %s' % [from(bid)[:from], to(bid)[:to]] }
end
|
.price(bid) ⇒ Object
74
75
76
|
# File 'app/serializers/lease/bid_serializer.rb', line 74
def price(bid)
{ price: bid.price }
end
|
.price_percent(bid) ⇒ Object
78
79
80
|
# File 'app/serializers/lease/bid_serializer.rb', line 78
def price_percent(bid)
{ price_percent: bid.price_percent }
end
|
.state(bid) ⇒ Object
154
155
156
|
# File 'app/serializers/lease/bid_serializer.rb', line 154
def state(bid)
{ state: bid.state }
end
|
.to(bid) ⇒ Object
150
151
152
|
# File 'app/serializers/lease/bid_serializer.rb', line 150
def to(bid)
{ to: format_date(bid.to, @opts[:locale]) }
end
|