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 +4 -4
- data/lib/web_utils.rb +7 -2
- data/test/test_web_utils.rb +7 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 012337d85ac2f57712f990bc66e4a1d17d3112d9
|
4
|
+
data.tar.gz: 261669c70174e678cf1d8bea94150d42a8b10dc4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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
|
-
|
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
|
|
data/test/test_web_utils.rb
CHANGED
@@ -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.
|
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:
|
11
|
+
date: 2018-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|