Class: BoatSerializer

Inherits:
AbstractSerializer show all
Defined in:
app/serializers/boat_serializer.rb

Class Method Summary collapse

Methods inherited from AbstractSerializer

opts

Class Method Details

.available_attributesObject



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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/serializers/boat_serializer.rb', line 4

def available_attributes
  i[
    charter_1_hour_low_usd
    charter_1_hour_low_rub
    charter_1_hour_low_eur
    charter_1_day_low_usd
    charter_1_day_low_rub
    charter_1_day_low_eur
    charter_1_week_low_usd
    charter_1_week_low_rub
    charter_1_week_low_eur
    charter_1_month_low_usd
    charter_1_month_low_rub
    charter_1_month_low_eur
    charter_1_hour_high_usd
    charter_1_hour_high_rub
    charter_1_hour_high_eur
    charter_1_day_high_usd
    charter_1_day_high_rub
    charter_1_day_high_eur
    charter_1_week_high_usd
    charter_1_week_high_rub
    charter_1_week_high_eur
    charter_1_month_high_usd
    charter_1_month_high_rub
    charter_1_month_high_eur
    sale_price_usd
    sale_price_rub
    sale_price_eur
    id
    picture_medium_url
    name
    builder
    short_description
    per_season
    price
    price_discount
    guests_total
    guest_cabins
    crew_total
    built_year
    refit_year
    boat_model
    location_address
    latitude
    boat_type_id
    boat_length_metrics
    boat_length_metrics_meters
    boat_length_metrics_ft
    boat_beam_metrics
    boat_beam_metrics_ft
    boat_beam_metrics_meters
    boat_draft_metrics
    boat_draft_metrics_ft
    boat_draft_metrics_meters
  ].freeze
end

.boat_beam_metrics(boat) ⇒ Object



189
190
191
192
# File 'app/serializers/boat_serializer.rb', line 189

def boat_beam_metrics(boat)
  value = ::Lib::Boats::Dimensions.boatbeam(boat, @opts[:uom])
  { boat_beam_metrics: value }
end

.boat_beam_metrics_ft(boat) ⇒ Object



194
195
196
# File 'app/serializers/boat_serializer.rb', line 194

def boat_beam_metrics_ft(boat)
  { boat_beam_metrics_ft: boat.boat_beam_metrics_ft }
end

.boat_beam_metrics_meters(boat) ⇒ Object



198
199
200
# File 'app/serializers/boat_serializer.rb', line 198

def boat_beam_metrics_meters(boat)
  { boat_beam_metrics_meters: boat.boat_beam_metrics_meters }
end

.boat_draft_metrics(boat) ⇒ Object



202
203
204
205
# File 'app/serializers/boat_serializer.rb', line 202

def boat_draft_metrics(boat)
  value = ::Lib::Boats::Dimensions.boatdraft(boat, @opts[:uom])
  { boat_draft_metrics: value }
end

.boat_draft_metrics_ft(boat) ⇒ Object



207
208
209
# File 'app/serializers/boat_serializer.rb', line 207

def boat_draft_metrics_ft(boat)
  { boat_draft_metrics_ft: boat.boat_draft_metrics_ft }
end

.boat_draft_metrics_meters(boat) ⇒ Object



211
212
213
# File 'app/serializers/boat_serializer.rb', line 211

def boat_draft_metrics_meters(boat)
  { boat_draft_metrics_meters: boat.boat_draft_metrics_meters }
end

.boat_length_metrics(boat) ⇒ Object



176
177
178
179
# File 'app/serializers/boat_serializer.rb', line 176

def boat_length_metrics(boat)
  value = ::Lib::Boats::Dimensions.boatlength(boat, @opts[:uom])
  { boat_length_metrics: value }
end

.boat_length_metrics_ft(boat) ⇒ Object



185
186
187
# File 'app/serializers/boat_serializer.rb', line 185

def boat_length_metrics_ft(boat)
  { boat_length_metrics_ft: boat.boat_length_metrics_ft }
end

.boat_length_metrics_meters(boat) ⇒ Object



181
182
183
# File 'app/serializers/boat_serializer.rb', line 181

def boat_length_metrics_meters(boat)
  { boat_length_metrics_meters: boat.boat_length_metrics_meters }
end

.boat_model(boat) ⇒ Object



156
157
158
# File 'app/serializers/boat_serializer.rb', line 156

def boat_model(boat)
  { boat_model: boat.boat_model }
end

.boat_type_id(boat) ⇒ Object



172
173
174
# File 'app/serializers/boat_serializer.rb', line 172

def boat_type_id(boat)
  { boat_type_id: boat.boat_type_id }
end

.builder(boat) ⇒ Object



94
95
96
# File 'app/serializers/boat_serializer.rb', line 94

def builder(boat)
  { builder: boat.builder }
end

.built_year(boat) ⇒ Object



147
148
149
# File 'app/serializers/boat_serializer.rb', line 147

def built_year(boat)
  { built_year: boat.built_year || '' }
end

.charter_1_day_high_eur(boat) ⇒ Object



288
289
290
# File 'app/serializers/boat_serializer.rb', line 288

def charter_1_day_high_eur(boat)
  { charter_1_day_high_eur: boat.charter_1_day_high_eur || '' }
end

.charter_1_day_high_rub(boat) ⇒ Object



284
285
286
# File 'app/serializers/boat_serializer.rb', line 284

def charter_1_day_high_rub(boat)
  { charter_1_day_high_rub: boat.charter_1_day_high_rub || '' }
end

.charter_1_day_high_usd(boat) ⇒ Object



280
281
282
# File 'app/serializers/boat_serializer.rb', line 280

def charter_1_day_high_usd(boat)
  { charter_1_day_high_usd: boat.charter_1_day_high_usd || '' }
end

.charter_1_day_low_eur(boat) ⇒ Object



238
239
240
# File 'app/serializers/boat_serializer.rb', line 238

def charter_1_day_low_eur(boat)
  { charter_1_day_low_eur: boat.charter_1_day_low_eur || '' }
end

.charter_1_day_low_rub(boat) ⇒ Object



234
235
236
# File 'app/serializers/boat_serializer.rb', line 234

def charter_1_day_low_rub(boat)
  { charter_1_day_low_rub: boat.charter_1_day_low_rub || '' }
end

.charter_1_day_low_usd(boat) ⇒ Object



230
231
232
# File 'app/serializers/boat_serializer.rb', line 230

def charter_1_day_low_usd(boat)
  { charter_1_day_low_usd: boat.charter_1_day_low_usd || '' }
end

.charter_1_hour_high_eur(boat) ⇒ Object



276
277
278
# File 'app/serializers/boat_serializer.rb', line 276

def charter_1_hour_high_eur(boat)
  { charter_1_hour_high_eur: boat.charter_1_hour_high_eur || '' }
end

.charter_1_hour_high_rub(boat) ⇒ Object



272
273
274
# File 'app/serializers/boat_serializer.rb', line 272

def charter_1_hour_high_rub(boat)
  { charter_1_hour_high_rub: boat.charter_1_hour_high_rub || '' }
end

.charter_1_hour_high_usd(boat) ⇒ Object

–[high]———————————————————————————————————–



268
269
270
# File 'app/serializers/boat_serializer.rb', line 268

def charter_1_hour_high_usd(boat)
  { charter_1_hour_high_usd: boat.charter_1_hour_high_usd || '' }
end

.charter_1_hour_low_eur(boat) ⇒ Object



226
227
228
# File 'app/serializers/boat_serializer.rb', line 226

def charter_1_hour_low_eur(boat)
  { charter_1_hour_low_eur: boat.charter_1_hour_low_eur || '' }
end

.charter_1_hour_low_rub(boat) ⇒ Object



222
223
224
# File 'app/serializers/boat_serializer.rb', line 222

def charter_1_hour_low_rub(boat)
  { charter_1_hour_low_rub: boat.charter_1_hour_low_rub || '' }
end

.charter_1_hour_low_usd(boat) ⇒ Object

–[low]———————————————————————————————————–



218
219
220
# File 'app/serializers/boat_serializer.rb', line 218

def charter_1_hour_low_usd(boat)
  { charter_1_hour_low_usd: boat.charter_1_hour_low_usd || '' }
end

.charter_1_month_high_eur(boat) ⇒ Object



312
313
314
# File 'app/serializers/boat_serializer.rb', line 312

def charter_1_month_high_eur(boat)
  { charter_1_month_high_eur: boat.charter_1_month_high_eur || '' }
end

.charter_1_month_high_rub(boat) ⇒ Object



308
309
310
# File 'app/serializers/boat_serializer.rb', line 308

def charter_1_month_high_rub(boat)
  { charter_1_month_high_rub: boat.charter_1_month_high_rub || '' }
end

.charter_1_month_high_usd(boat) ⇒ Object



304
305
306
# File 'app/serializers/boat_serializer.rb', line 304

def charter_1_month_high_usd(boat)
  { charter_1_month_high_usd: boat.charter_1_month_high_usd || '' }
end

.charter_1_month_low_eur(boat) ⇒ Object



262
263
264
# File 'app/serializers/boat_serializer.rb', line 262

def charter_1_month_low_eur(boat)
  { charter_1_month_low_eur: boat.charter_1_month_low_eur || '' }
end

.charter_1_month_low_rub(boat) ⇒ Object



258
259
260
# File 'app/serializers/boat_serializer.rb', line 258

def charter_1_month_low_rub(boat)
  { charter_1_month_low_rub: boat.charter_1_month_low_rub || '' }
end

.charter_1_month_low_usd(boat) ⇒ Object



254
255
256
# File 'app/serializers/boat_serializer.rb', line 254

def charter_1_month_low_usd(boat)
  { charter_1_month_low_usd: boat.charter_1_month_low_usd || '' }
end

.charter_1_week_high_eur(boat) ⇒ Object



300
301
302
# File 'app/serializers/boat_serializer.rb', line 300

def charter_1_week_high_eur(boat)
  { charter_1_week_high_eur: boat.charter_1_week_high_eur || '' }
end

.charter_1_week_high_rub(boat) ⇒ Object



296
297
298
# File 'app/serializers/boat_serializer.rb', line 296

def charter_1_week_high_rub(boat)
  { charter_1_week_high_rub: boat.charter_1_week_high_rub || '' }
end

.charter_1_week_high_usd(boat) ⇒ Object



292
293
294
# File 'app/serializers/boat_serializer.rb', line 292

def charter_1_week_high_usd(boat)
  { charter_1_week_high_usd: boat.charter_1_week_high_usd || '' }
end

.charter_1_week_low_eur(boat) ⇒ Object



250
251
252
# File 'app/serializers/boat_serializer.rb', line 250

def charter_1_week_low_eur(boat)
  { charter_1_week_low_eur: boat.charter_1_week_low_eur || '' }
end

.charter_1_week_low_rub(boat) ⇒ Object



246
247
248
# File 'app/serializers/boat_serializer.rb', line 246

def charter_1_week_low_rub(boat)
  { charter_1_week_low_rub: boat.charter_1_week_low_rub || '' }
end

.charter_1_week_low_usd(boat) ⇒ Object



242
243
244
# File 'app/serializers/boat_serializer.rb', line 242

def charter_1_week_low_usd(boat)
  { charter_1_week_low_usd: boat.charter_1_week_low_usd || '' }
end

.crew_total(boat) ⇒ Object



143
144
145
# File 'app/serializers/boat_serializer.rb', line 143

def crew_total(boat)
  { crew_total: boat.crew_total || '' }
end

.default_optsObject



62
63
64
65
66
67
68
69
# File 'app/serializers/boat_serializer.rb', line 62

def default_opts
  {
    uom:         'ft',
    currency:    'USD',
    locale:      'en',
    is_for_rent: true
  }
end

.guest_cabins(boat) ⇒ Object



139
140
141
# File 'app/serializers/boat_serializer.rb', line 139

def guest_cabins(boat)
  { guest_cabins: boat.guest_cabins || '' }
end

.guests_total(boat) ⇒ Object



135
136
137
# File 'app/serializers/boat_serializer.rb', line 135

def guests_total(boat)
  { guests_total: boat.guests_total || '' }
end

.id(boat) ⇒ Object



75
76
77
# File 'app/serializers/boat_serializer.rb', line 75

def id(boat)
  { id: boat.id }
end

.latitude(boat) ⇒ Object



164
165
166
# File 'app/serializers/boat_serializer.rb', line 164

def latitude(boat)
  { latitude: boat.latitude }
end

.location_address(boat) ⇒ Object



160
161
162
# File 'app/serializers/boat_serializer.rb', line 160

def location_address(boat)
  { location_address: boat.location_address }
end

.longitude(boat) ⇒ Object



168
169
170
# File 'app/serializers/boat_serializer.rb', line 168

def longitude(boat)
  { longitude: boat.longitude }
end

.name(boat) ⇒ Object



90
91
92
# File 'app/serializers/boat_serializer.rb', line 90

def name(boat)
  { name: boat.name }
end

.per_season(boat) ⇒ Object

per day, per week; в день, в час, за месяц;



105
106
107
108
109
110
111
112
# File 'app/serializers/boat_serializer.rb', line 105

def per_season(boat)
  season_key = ::Lib::Boats::RentPricePerSeason.spot_rentprice_id(boat, @opts[:currency], @opts[:rent_price_id]).gsub(/_low|_high/, '')
  #=> charter_1_week_low, charter_1_day_high
  translate  = I18n.t("boat.rent_price.per_#{season_key}")
  value      = @opts[:is_for_rent] ? translate : ''

  { per_season: value }
end

.picture_medium_url(boat) ⇒ Object

noinspection RubyResolve



80
81
82
83
84
85
86
87
88
# File 'app/serializers/boat_serializer.rb', line 80

def picture_medium_url(boat)
  url = if boat.boat_photo.present?
          boat.boat_photo.picture.url(:medium).gsub('\'', ''')
        else
          ''
        end

  { picture_medium_url: url }
end

.price(boat) ⇒ Object

₽ 293,885



115
116
117
118
119
120
121
122
123
# File 'app/serializers/boat_serializer.rb', line 115

def price(boat)
  value = if @opts[:is_for_rent]
            ::Lib::Boats::RentPricePerSeason.price(boat, @opts[:currency], @opts[:rent_price_id])
          else
            ::Lib::Boats::SalePrice.price(boat, @opts[:currency])
          end

  { price: value }
end

.price_discount(boat) ⇒ Object

12%



126
127
128
129
130
131
132
133
# File 'app/serializers/boat_serializer.rb', line 126

def price_discount(boat)
  value = if @opts[:is_for_rent]
            ::Lib::Boats::RentPricePerSeason.price_discount(boat, @opts[:currency])
          else
            ::Lib::Boats::SalePrice.price_discount(boat)
          end
  { price_discount: value }
end

.refit_year(boat) ⇒ Object



151
152
153
154
# File 'app/serializers/boat_serializer.rb', line 151

def refit_year(boat)
  value = boat.refit_year || ''
  { refit_year: value }
end

.sale_price_eur(boat) ⇒ Object



326
327
328
# File 'app/serializers/boat_serializer.rb', line 326

def sale_price_eur(boat)
  { sale_price_eur: boat.sale_price_eur || '' }
end

.sale_price_rub(boat) ⇒ Object



322
323
324
# File 'app/serializers/boat_serializer.rb', line 322

def sale_price_rub(boat)
  { sale_price_rub: boat.sale_price_rub || '' }
end

.sale_price_usd(boat) ⇒ Object

–[sale]———————————————————————————————————-



318
319
320
# File 'app/serializers/boat_serializer.rb', line 318

def sale_price_usd(boat)
  { sale_price_usd: boat.sale_price_usd || '' }
end

.serialize(model, attributes: available_attributes, opts: {}) ⇒ Object



71
72
73
# File 'app/serializers/boat_serializer.rb', line 71

def serialize(model, attributes: available_attributes, opts: {})
  super(model, attributes: attributes, opts: default_opts.merge(opts))
end

.short_description(boat) ⇒ Object



98
99
100
101
102
# File 'app/serializers/boat_serializer.rb', line 98

def short_description(boat)
  attr  = 'short_description_%s' % @opts[:locale]
  value = boat.send(attr.to_sym) || ''
  { short_description: value }
end