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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/serializers/boat_serializer.rb', line 4

def available_attributes
  i[
    boat_beam_metrics
    boat_beam_metrics_ft
    boat_beam_metrics_meters
    boat_contacts
    boat_draft_metrics
    boat_draft_metrics_ft
    boat_draft_metrics_meters
    boat_hull_id
    boat_length_metrics
    boat_length_metrics_ft
    boat_length_metrics_meters
    boat_model
    boat_photos
    boat_type
    boat_type_id
    builder
    built_year
    charter_1_day_high_discount
    charter_1_day_high_eur
    charter_1_day_high_rub
    charter_1_day_high_usd
    charter_1_day_low_discount
    charter_1_day_low_eur
    charter_1_day_low_rub
    charter_1_day_low_usd
    charter_1_hour_high_discount
    charter_1_hour_high_eur
    charter_1_hour_high_rub
    charter_1_hour_high_usd
    charter_1_hour_low_discount
    charter_1_hour_low_eur
    charter_1_hour_low_rub
    charter_1_hour_low_usd
    charter_1_month_high_discount
    charter_1_month_high_eur
    charter_1_month_high_rub
    charter_1_month_high_usd
    charter_1_month_low_discount
    charter_1_month_low_eur
    charter_1_month_low_rub
    charter_1_month_low_usd
    charter_1_week_high_discount
    charter_1_week_high_eur
    charter_1_week_high_rub
    charter_1_week_high_usd
    charter_1_week_low_discount
    charter_1_week_low_eur
    charter_1_week_low_rub
    charter_1_week_low_usd
    crew_total
    guest_cabins
    guests_total
    hull_material
    id
    interior_designer
    latitude
    location_address
    longitude
    main_boat_photo_id
    motor
    name
    name_builder
    naval_architect
    per_season
    picture_medium_url
    price
    price_discount
    refit_year
    sale_price_discount
    sale_price_eur
    sale_price_rub
    sale_price_usd
    short_description
    state
  ].freeze
end

.boat_beam_metrics(boat) ⇒ Object



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

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

.boat_beam_metrics_ft(boat) ⇒ Object



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

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

.boat_beam_metrics_meters(boat) ⇒ Object



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

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

.boat_contacts(boat) ⇒ Object

Контакты владельцев: то, что приходит в boat_users_attributes из админской формы



458
459
460
461
462
463
464
465
# File 'app/serializers/boat_serializer.rb', line 458

def boat_contacts(boat)
  boat_contacts = boat.boat_users.map do |user|
    {
      user_id: user.user_id
    }
  end
  { boat_contacts: boat_contacts }
end

.boat_draft_metrics(boat) ⇒ Object



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

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

.boat_draft_metrics_ft(boat) ⇒ Object



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

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

.boat_draft_metrics_meters(boat) ⇒ Object



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

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

.boat_hull_id(boat) ⇒ Object



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

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

.boat_length_metrics(boat) ⇒ Object



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

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

.boat_length_metrics_ft(boat) ⇒ Object



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

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

.boat_length_metrics_meters(boat) ⇒ Object



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

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

.boat_model(boat) ⇒ Object



216
217
218
# File 'app/serializers/boat_serializer.rb', line 216

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

.boat_photos(boat) ⇒ Object



444
445
446
447
448
449
450
451
452
453
454
455
# File 'app/serializers/boat_serializer.rb', line 444

def boat_photos(boat)
  # FIXME:: выяснить, нужно ли всётаки использовать .gsub('\'', ''') для строк с путями к фоткам?
  boat_photos = boat.boat_photos.map do |boat_photo|
    {
      id:           boat_photo.id,
      gallery_path: boat_photo.picture.url(:gallery),
      medium_path:  boat_photo.picture.url(:medium),
      thumb_path:   boat_photo.picture.url(:thumb)
    }
  end
  { boat_photos: boat_photos }
end

.boat_type(boat) ⇒ Object



236
237
238
239
240
241
242
243
# File 'app/serializers/boat_serializer.rb', line 236

def boat_type(boat)
  {
      boat_type: {
          id:     boat.boat_type_id,
          title:  boat.boat_type&.name&.strip
      }
  }
end

.boat_type_id(boat) ⇒ Object



232
233
234
# File 'app/serializers/boat_serializer.rb', line 232

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

.builder(boat) ⇒ Object



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

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

.built_year(boat) ⇒ Object



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

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

.charter_1_day_high_discount(boat) ⇒ Object

–[discount]——————————————————————————————————



404
405
406
# File 'app/serializers/boat_serializer.rb', line 404

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

.charter_1_day_high_eur(boat) ⇒ Object



360
361
362
# File 'app/serializers/boat_serializer.rb', line 360

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



356
357
358
# File 'app/serializers/boat_serializer.rb', line 356

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



352
353
354
# File 'app/serializers/boat_serializer.rb', line 352

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

.charter_1_day_low_discount(boat) ⇒ Object



408
409
410
# File 'app/serializers/boat_serializer.rb', line 408

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

.charter_1_day_low_eur(boat) ⇒ Object



310
311
312
# File 'app/serializers/boat_serializer.rb', line 310

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



306
307
308
# File 'app/serializers/boat_serializer.rb', line 306

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



302
303
304
# File 'app/serializers/boat_serializer.rb', line 302

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

.charter_1_hour_high_discount(boat) ⇒ Object



412
413
414
# File 'app/serializers/boat_serializer.rb', line 412

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

.charter_1_hour_high_eur(boat) ⇒ Object



348
349
350
# File 'app/serializers/boat_serializer.rb', line 348

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



344
345
346
# File 'app/serializers/boat_serializer.rb', line 344

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]———————————————————————————————————–



340
341
342
# File 'app/serializers/boat_serializer.rb', line 340

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

.charter_1_hour_low_discount(boat) ⇒ Object



416
417
418
# File 'app/serializers/boat_serializer.rb', line 416

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

.charter_1_hour_low_eur(boat) ⇒ Object



298
299
300
# File 'app/serializers/boat_serializer.rb', line 298

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



294
295
296
# File 'app/serializers/boat_serializer.rb', line 294

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]———————————————————————————————————–



290
291
292
# File 'app/serializers/boat_serializer.rb', line 290

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

.charter_1_month_high_discount(boat) ⇒ Object



420
421
422
# File 'app/serializers/boat_serializer.rb', line 420

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

.charter_1_month_high_eur(boat) ⇒ Object



384
385
386
# File 'app/serializers/boat_serializer.rb', line 384

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



380
381
382
# File 'app/serializers/boat_serializer.rb', line 380

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



376
377
378
# File 'app/serializers/boat_serializer.rb', line 376

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

.charter_1_month_low_discount(boat) ⇒ Object



424
425
426
# File 'app/serializers/boat_serializer.rb', line 424

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

.charter_1_month_low_eur(boat) ⇒ Object



334
335
336
# File 'app/serializers/boat_serializer.rb', line 334

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



330
331
332
# File 'app/serializers/boat_serializer.rb', line 330

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



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

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

.charter_1_week_high_discount(boat) ⇒ Object



428
429
430
# File 'app/serializers/boat_serializer.rb', line 428

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

.charter_1_week_high_eur(boat) ⇒ Object



372
373
374
# File 'app/serializers/boat_serializer.rb', line 372

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



368
369
370
# File 'app/serializers/boat_serializer.rb', line 368

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



364
365
366
# File 'app/serializers/boat_serializer.rb', line 364

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

.charter_1_week_low_discount(boat) ⇒ Object



432
433
434
# File 'app/serializers/boat_serializer.rb', line 432

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

.charter_1_week_low_eur(boat) ⇒ Object



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

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



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

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



314
315
316
# File 'app/serializers/boat_serializer.rb', line 314

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

.crew_total(boat) ⇒ Object



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

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

.default_optsObject



83
84
85
86
87
88
89
90
# File 'app/serializers/boat_serializer.rb', line 83

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

.guest_cabins(boat) ⇒ Object



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

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

.guests_total(boat) ⇒ Object



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

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

.hull_material(boat) ⇒ Object



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

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

.id(boat) ⇒ Object



96
97
98
# File 'app/serializers/boat_serializer.rb', line 96

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

.interior_designer(boat) ⇒ Object



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

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

.latitude(boat) ⇒ Object



224
225
226
# File 'app/serializers/boat_serializer.rb', line 224

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

.location_address(boat) ⇒ Object



220
221
222
# File 'app/serializers/boat_serializer.rb', line 220

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

.longitude(boat) ⇒ Object



228
229
230
# File 'app/serializers/boat_serializer.rb', line 228

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

.main_boat_photo_id(boat) ⇒ Object



142
143
144
145
146
147
148
# File 'app/serializers/boat_serializer.rb', line 142

def main_boat_photo_id(boat)
  boat_photo_id = if boat.boat_photo.present?
                    boat.boat_photo.id
                  end

  { main_boat_photo_id: boat_photo_id }
end

.motor(boat) ⇒ Object



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

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

.name(boat) ⇒ Object



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

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

.name_builder(boat) ⇒ Object

Для страницы просмотра лодки

example: Carpe Diem by Lazzara example: Ismail



112
113
114
115
116
117
118
119
120
121
# File 'app/serializers/boat_serializer.rb', line 112

def name_builder(boat)
  arr = []
  arr << boat.name&.strip
  if boat.builder.present?
    arr << I18n.t('boat.builder.prefix')
    arr << boat.builder.strip
  end

  { name_builder: arr * ' ' }
end


104
105
106
# File 'app/serializers/boat_serializer.rb', line 104

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

.per_season(boat) ⇒ Object

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



161
162
163
164
165
166
167
168
# File 'app/serializers/boat_serializer.rb', line 161

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



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

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

  { picture_medium_url: url }
end

.price(boat) ⇒ Object

₽ 293,885



171
172
173
174
175
176
177
178
179
# File 'app/serializers/boat_serializer.rb', line 171

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%



182
183
184
185
186
187
188
189
# File 'app/serializers/boat_serializer.rb', line 182

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



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

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

.sale_price_discount(boat) ⇒ Object



436
437
438
# File 'app/serializers/boat_serializer.rb', line 436

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

.sale_price_eur(boat) ⇒ Object



398
399
400
# File 'app/serializers/boat_serializer.rb', line 398

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

.sale_price_rub(boat) ⇒ Object



394
395
396
# File 'app/serializers/boat_serializer.rb', line 394

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

.sale_price_usd(boat) ⇒ Object

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



390
391
392
# File 'app/serializers/boat_serializer.rb', line 390

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

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



92
93
94
# File 'app/serializers/boat_serializer.rb', line 92

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

.short_description(boat) ⇒ Object



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

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

.state(boat) ⇒ Object



440
441
442
# File 'app/serializers/boat_serializer.rb', line 440

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