c80_shared 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a2706a20ad0ad66be170e9764feeb12b30a3f02010e7d9c7dbf84cbec410f9e5
4
- data.tar.gz: 876330689d717eadc3198b4413622f31bd70c0b5160d18cb511a86a0a62502d1
3
+ metadata.gz: b236e08513a15d9ca9dd41382641ee82d24158b0a0850c8c907ebb7528330a2f
4
+ data.tar.gz: e80c6d7d2c3f12a153aac7c82abac231374f29ac616b11166803c52c6397c1c9
5
5
  SHA512:
6
- metadata.gz: 0463f94d546a66b8e3d437e118989bd00b2ab8c014b8e78401b826cf48cf293f8a5fb5dc2845348a2fb38d5707c95ecdcae0dc75a907e95c113dd5728a42b52b
7
- data.tar.gz: ca23d280cffc94848cdcff0be3904c675e12d317b586ecf8fe55b6cacf1c89e0ba1c9379d9e7396de319bc0720fca80ac7d87489bbd4eca7eb1a66363fd823b1
6
+ metadata.gz: bbc0039d84644da11ff2aecd5cfbaf101e33b6bb1bb6e11c376d0290866bbe8d9ef21f8d737c59830539ec3fee54532f489fa2e8abbf75446dbf04d7ca2bdc15
7
+ data.tar.gz: ee4753dda77eac6ed36e1cd30c16c8d50dcfab8885fc07b0895e162ea04a2425e6ce0c21555d23437306dda72020338cf718898108e05c15bdfdc10f035afe3b
@@ -0,0 +1,6 @@
1
+ module Dicts
2
+ class RentSkipType < ::Dict
3
+ SKIPPERED = new(1, 'true')
4
+ BAREBOAT = new(2, 'false')
5
+ end
6
+ end
@@ -0,0 +1,24 @@
1
+ module Custom
2
+ module CurrencyHelper
3
+ def currency_symbol
4
+ collection_name_by_id(t('static.currencies', default: ''), cookies[:currency]) || ''
5
+ end
6
+
7
+ def currency_for_label(options = {})
8
+ options[:prefix] ||= ', '
9
+ "#{options[:prefix]}#{currency_symbol}"
10
+ end
11
+
12
+ def currency_attribute_name(name)
13
+ Currency.attribute_name(cookies[:currency], name)
14
+ end
15
+
16
+ # 12 USD -> $ 12.00, EUR -> €,...
17
+ require_relative 'select_helper'
18
+ include ::Custom::SelectHelper
19
+ def num_to_cur(val, iso_code, locale)
20
+ unit = collection_name_by_id(I18n.t('static.currencies', default: ''), iso_code)
21
+ number_to_currency(val, unit: unit, locale: locale)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,19 @@
1
+ module Custom
2
+ module SelectHelper
3
+ def collection_name_by_id(collection, id)
4
+ return false if collection.empty?
5
+
6
+ element = collection.find { |hash| hash[:id] == id }
7
+ element.try(:fetch, :name)
8
+ end
9
+
10
+ def collection_for_select(collection, name, id, options = {})
11
+ return [] unless collection.is_a?(Array)
12
+
13
+ collection = collection.map { |h| [ h[name], h[id] ] }
14
+ collection = options_for_select(collection, options[:value]) if options[:options_for_select].present?
15
+ collection
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,102 @@
1
+ module Lease
2
+ class BidSerializer < ::AbstractSerializer
3
+
4
+ extend ::Site::TimeHelper
5
+ extend ::Custom::CurrencyHelper
6
+ extend ::ActionView::Helpers::NumberHelper
7
+
8
+ class << self
9
+
10
+ def available_attributes
11
+ %i[
12
+ id
13
+ account_id
14
+ inquiry_id
15
+ boat_id
16
+ boat
17
+ price
18
+ currency
19
+ state
20
+ from
21
+ to
22
+ period
23
+ duration
24
+ human_price
25
+ ].freeze
26
+ end
27
+
28
+ def id(bid)
29
+ { id: bid.id }
30
+ end
31
+
32
+ def account_id(bid)
33
+ { account_id: bid.account_id }
34
+ end
35
+
36
+ def inquiry_id(bid)
37
+ { inquiry_id: bid.inquiry_id }
38
+ end
39
+
40
+ def boat_id(bid)
41
+ { boat_id: bid.boat_id }
42
+ end
43
+
44
+ def boat(bid)
45
+ boat = bid.boat
46
+ {
47
+ boat: {
48
+ id: boat.id,
49
+ img_url: (boat.boat_photo.picture.url(:thumb) if boat.boat_photo.present?),
50
+ name: boat.name,
51
+ type: (boat.boat_type.name rescue nil)
52
+ }
53
+ }
54
+ end
55
+
56
+ def price(bid)
57
+ { price: bid.price }
58
+ end
59
+
60
+ def currency(bid)
61
+ { currency: bid.currency }
62
+ end
63
+
64
+ def human_price(bid)
65
+ val = nil
66
+ if bid.price.present? && bid.currency.present?
67
+ val = num_to_cur(bid.price, bid.currency, @opts[:locale])
68
+ end
69
+ { human_price: val }
70
+ end
71
+
72
+ def period(bid)
73
+ { period: '%s - %s' % [from(bid)[:from], to(bid)[:to]] }
74
+ end
75
+
76
+ def duration(bid)
77
+ distance = (bid.to - bid.from).to_i / 24 / 60 / 60
78
+ distance = distance.zero? ? 1 : distance
79
+ uom = I18n.t('activerecord.labels.lease/bid.day', count: distance)
80
+ {
81
+ duration: {
82
+ distance: distance,
83
+ uom: uom
84
+ }
85
+ }
86
+ end
87
+
88
+ def from(bid)
89
+ { from: format_date(bid.from, @opts[:locale]) }
90
+ end
91
+
92
+ def to(bid)
93
+ { to: format_date(bid.to, @opts[:locale]) }
94
+ end
95
+
96
+ def state(bid)
97
+ { state: bid.state }
98
+ end
99
+
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails gems
3
+ # installed from the root of your application.
4
+
5
+ ENGINE_ROOT = File.expand_path('../..', __FILE__)
6
+ ENGINE_PATH = File.expand_path('../../lib/c80_shared/engine', __FILE__)
7
+
8
+ # Set up gems listed in the Gemfile.
9
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
10
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
11
+
12
+ require 'rails/all'
13
+ require 'rails/engine/commands'
@@ -0,0 +1,5 @@
1
+ en:
2
+ rent_skip_type:
3
+ 'nil': 'Not skippered (bareboat)'
4
+ 'true': 'Skippered'
5
+ 'false': 'Not skippered (bareboat)'
@@ -0,0 +1,5 @@
1
+ ru:
2
+ rent_skip_type:
3
+ 'nil': 'Без капитана'
4
+ 'true': 'С капитаном'
5
+ 'false': 'Без капитана'
@@ -0,0 +1,5 @@
1
+ module C80Shared
2
+ class Engine < ::Rails::Engine
3
+ config.i18n.load_path += Dir[config.root.join('config', 'locales', '*','*.{yml}').to_s]
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module C80Shared
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: c80_shared
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - C80609A
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-11-06 00:00:00.000000000 Z
11
+ date: 2018-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -50,14 +50,22 @@ files:
50
50
  - Gemfile
51
51
  - README.md
52
52
  - app/dicts/email_token_subj.rb
53
+ - app/dicts/rent_skip_type.rb
54
+ - app/helpers/custom/currency_helper.rb
55
+ - app/helpers/custom/select_helper.rb
53
56
  - app/helpers/site/time_helper.rb
57
+ - app/serializers/lease/bid_serializer.rb
54
58
  - app/serializers/lease/inquiry_serializer.rb
55
59
  - bin/console
60
+ - bin/rails
56
61
  - bin/setup
57
62
  - c80_shared.gemspec
63
+ - config/locales/rent_skip_type/en.yml
64
+ - config/locales/rent_skip_type/ru.yml
58
65
  - lib/c80_shared.rb
59
66
  - lib/c80_shared/abstract_serializer.rb
60
67
  - lib/c80_shared/dict.rb
68
+ - lib/c80_shared/engine.rb
61
69
  - lib/c80_shared/middleware/images_proxy.rb
62
70
  - lib/c80_shared/version.rb
63
71
  homepage: http://google.com