istox 0.3.6 → 0.3.8

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: 72f9de96be0ee13aa39f738c058ed8f0a2d3266d7c169a5227fccf31539f3fc6
4
- data.tar.gz: 0615affb6b22aba8d490a522a5227f101e978025f974630f710d7a45cebaba2d
3
+ metadata.gz: '08ae3c962e156368285e8e07ea655d428b93310ab4137a370dd6ab95f7ac00cc'
4
+ data.tar.gz: 6f6c813fee420de9cd06e0175069e8f8f2e3b2d70eebe8e792962f3cac419190
5
5
  SHA512:
6
- metadata.gz: bf682beddd73d82fefaaf41fa4fceca53b299044a79e4cd331e9209910a725ff062f63d81152e67378b02a5221842006308779946ae223fb02ff7c9fa6d0950b
7
- data.tar.gz: 5a1f2de1d26156629b1ebf08fc276bb02c7246f0f2290210fa14010c37bca7b6988799732cf743790ecdacaf87a7b65f8dcb76c70fefb3b73ac9f3cc93886594
6
+ metadata.gz: 534957ad873114132ca7fb35d79570f72c6020785d8bb7b71d7935fd98e6d2cb42d82166270dacdc6cf0f44dc8b649af80ec9724e2f022ce3646b0cbdf950a35
7
+ data.tar.gz: 945b8a9e2bf22dfccd62c2a0c7a3d38cf0c682c095d8ef28ddcfa66f74388e7891e31389b986c0351537cf061cb4c54c8ae789957d3f1492a349b65170b1071f
@@ -10,8 +10,8 @@ module Istox
10
10
  input = ::BigDecimal.new(input.to_s).round(precision, round_mode)
11
11
 
12
12
  input = input.abs if abs_num
13
-
14
- result = format("%.#{precision}f", input)
13
+ # result = format("%.#{precision}f", input) # may produce floating point error
14
+ result = (input.truncate(precision).to_s('F') + '000000000000000000')[/.*\..{#{precision}}/]
15
15
 
16
16
  parts = result.to_s.split('.')
17
17
  parts[0].gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, '\\1,')
@@ -19,7 +19,7 @@ module Istox
19
19
  end
20
20
 
21
21
  # format a money, eg. 20000.134 > SGD 20,000.14, position can be :front or :behind, abs_num: whether to absolute the number
22
- def money(input, round_mode: :half_up, precision: nil, currency:, position: :front, abs_num: false, hide_currency: false)
22
+ def money(input, currency:, round_mode: :half_up, precision: nil, position: :front, abs_num: false, hide_currency: false)
23
23
  # precision = ::Istox::CommonHelper.get_currency_decimal(currency, precision)
24
24
 
25
25
  decimal_place = if precision.present?
@@ -23,15 +23,20 @@ module Istox
23
23
 
24
24
  def call(host_type, service, method, grpc_retries_count: 1, **keyword_args)
25
25
  execute(host_type, service, method, **keyword_args)
26
- rescue Gruf::Client::Errors::Unavailable => e
27
- # will retry three times with 1 seconds sleep between if there is a Unavailable error thrown from GRPC
28
- if grpc_retries_count < 3
29
- log.warn "GRPC failed to connect to #{host_type}, retrying after 1 seconds, retry count: #{grpc_retries_count}/3"
30
- sleep 1
31
- reinitiate_service(host_type, service)
32
- call(host_type, service, method, grpc_retries_count: grpc_retries_count + 1, **keyword_args)
26
+ rescue Gruf::Client::Errors => e
27
+ if e.is_a? Gruf::Client::Errors::Unavailable
28
+ # will retry three times with 1 seconds sleep between if there is a Unavailable error thrown from GRPC
29
+ if grpc_retries_count < 3
30
+ log.warn "GRPC failed to connect to #{host_type}, retrying after 1 seconds, retry count: #{grpc_retries_count}/3"
31
+ sleep 1
32
+ reinitiate_service(host_type, service)
33
+ call(host_type, service, method, grpc_retries_count: grpc_retries_count + 1, **keyword_args)
34
+ else
35
+ log.fatal "GRPC unable connect to #{host_type}, throwing exception now."
36
+ raise e
37
+ end
33
38
  else
34
- log.fatal "GRPC unable connect to #{host_type}, throwing exception now."
39
+ log.info e
35
40
  raise e
36
41
  end
37
42
  end
@@ -69,10 +74,10 @@ module Istox
69
74
  grpc_client = @@services[get_key(host_type, service)]
70
75
 
71
76
  if grpc_client
72
- return grpc_client
77
+ grpc_client
73
78
  else
74
79
  reinitiate_service(host_type, service)
75
- return @@services[get_key(host_type, service)]
80
+ @@services[get_key(host_type, service)]
76
81
  end
77
82
  end
78
83
 
data/lib/istox/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Istox
2
- VERSION = '0.3.6'.freeze
2
+ VERSION = '0.3.8'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: istox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.3.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Siong Leng
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-27 00:00:00.000000000 Z
11
+ date: 2023-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: amazing_print