web-utils 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6888ae28ec9b1db76faa21a4cfbe1b26a8704802
4
- data.tar.gz: 4644b857b3a97e1a7d5c74dc1deec0e38ada30a2
3
+ metadata.gz: 012337d85ac2f57712f990bc66e4a1d17d3112d9
4
+ data.tar.gz: 261669c70174e678cf1d8bea94150d42a8b10dc4
5
5
  SHA512:
6
- metadata.gz: 891c7dad402974ecef9574be2b9c185a5aefec9a914169ac453d7c0af233b890e2a8ee050228fe47823459c9cac76bfafda26c2c2b0b301385af8b4481242528
7
- data.tar.gz: '092bb89b176b06a8a6ff84438fa86ae2e2d4b02b4f343fc917ee17d06fac3732674be4e75273d6480c9a88216e27d60934b1a87b006bd801632ea0685dcab34b'
6
+ metadata.gz: f23190c3b3da2094b4de3e8162227d677a121c33c7851b1b044281b5897cafa50936382f80ab0d753fb19c014fd6053135e7913acba24b482ad71e459fabffdb
7
+ data.tar.gz: b4679b9a9305809a82d96356fd429222bb364914eadfff14d73d6243973cf8f89a3fe74615ea8efc729e99b6ca8ee1cfc9fb6e21c17d5bc601358fd4183ab033
data/lib/web_utils.rb CHANGED
@@ -5,7 +5,7 @@ require 'uri'
5
5
 
6
6
  module WebUtils
7
7
 
8
- VERSION = '0.0.5'
8
+ VERSION = '0.0.6'
9
9
 
10
10
  # Most methods are supposed to be as simple as possible
11
11
  # and just cover most cases.
@@ -248,7 +248,12 @@ module WebUtils
248
248
  unless string.is_a?(String)
249
249
  raise(TypeError, 'The price needs to be parsed from a String')
250
250
  end
251
- ("%.2f" % string.gsub(/[^\d\.\-]/, '')).gsub(/\./,'').to_i
251
+ string = string.gsub(/[^\d\.\-,]/, '')
252
+ if string[/\.\d\d\d$/] or string[/,\d\d?$/]
253
+ # comma-based price
254
+ string = string.tr '.,', ',.'
255
+ end
256
+ ("%.2f" % string.gsub(/,/, '')).gsub(/\./,'').to_i
252
257
  end
253
258
  module_function :parse_price
254
259
 
@@ -87,6 +87,7 @@ describe WebUtils do
87
87
  ['View360', 'view-360'],
88
88
  ['View360Degree', 'view-360-degree'],
89
89
  ['Degree360::View', 'degree-360--view'],
90
+ ['Sphere3dView', 'sphere-3d-view'],
90
91
  ['RestAPI::Request::Post','rest-a-p-i--request--post'],
91
92
  ]
92
93
  }
@@ -498,6 +499,12 @@ describe WebUtils do
498
499
  it 'Ignores visual help but works with negative prices' do
499
500
  assert_equal -1234567890, utils.parse_price(' £-12,345,678.90 ')
500
501
  end
502
+ it 'Parses comma-based prices - french/german style' do
503
+ assert_equal 2390, utils.parse_price('23,90')
504
+ assert_equal 2390, utils.parse_price('23,9')
505
+ assert_equal 2000000, utils.parse_price('20.000')
506
+ assert_equal -1234567890, utils.parse_price(' £-12.345.678,90 ')
507
+ end
501
508
  it 'Raises when argument is not string' do
502
509
  assert_raises(TypeError) do
503
510
  utils.parse_price(42)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: web-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mickael Riga
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-24 00:00:00.000000000 Z
11
+ date: 2018-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack