dazzle 1.2 → 1.3.1
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 +4 -4
- data/lib/dazzle.rb +57 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f82897c84c5a403ffc8585d04327c2dc95dfed1a3cbacefade210fd13e73d869
|
4
|
+
data.tar.gz: 33995d2ebecf699ca10192262f39069471b5aa1b869c51e7ae83aea2b0755a84
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c279ed1069be06e7ca6becfcfb40e6e9395d1c23ad534dbcfad39ce22e35e7bc7e69316e7ac93e1454cf9e505ab19240657d39bda87780d6013f2971abdd496
|
7
|
+
data.tar.gz: 96c50329877d62a6db9bfb26a41a12126d061b1e827dd3ce35c140e2c1356045a8640af1856999e3ce520570558ed52f324c99197979405f2a757983773b80ac
|
data/lib/dazzle.rb
CHANGED
@@ -1,12 +1,64 @@
|
|
1
1
|
|
2
|
-
require 'rest-client'
|
2
|
+
require 'rest-client'
|
3
3
|
|
4
4
|
class Dazzling
|
5
5
|
|
6
|
-
def self.
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
def self.get_data_for_category(category)
|
7
|
+
|
8
|
+
category_data = RestClient.get 'http://demo6157752.mockable.io/' + category
|
9
|
+
|
10
|
+
arr = category_data.split("\"")
|
11
|
+
|
12
|
+
#remove last item
|
13
|
+
arr.pop
|
14
|
+
|
15
|
+
#remove first item
|
16
|
+
arr.shift
|
17
|
+
|
18
|
+
total = 0.0
|
19
|
+
|
20
|
+
average = 0.0
|
21
|
+
|
22
|
+
parsed = ""
|
23
|
+
|
24
|
+
counter = 0
|
25
|
+
|
26
|
+
for val in arr
|
27
|
+
counter = counter + 1
|
28
|
+
|
29
|
+
#every 2nd value is blank so ignore it
|
30
|
+
if counter % 2 == 1
|
31
|
+
|
32
|
+
val = val.gsub(":", "")
|
33
|
+
val = val.gsub(",", "")
|
34
|
+
|
35
|
+
num = Float(val) rescue nil
|
36
|
+
if !num.nil?
|
37
|
+
total = total + num
|
38
|
+
end
|
39
|
+
|
40
|
+
parsed << val + ","
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
total = total.round(2)
|
47
|
+
|
48
|
+
# +1 because the last empty space was removed
|
49
|
+
# /4 because in the original array generated from the 'split' function, every 4th value was a price
|
50
|
+
average = (total / ((counter + 1) / 4)).round(2)
|
51
|
+
|
52
|
+
parsed << "Total Price,"
|
53
|
+
|
54
|
+
parsed << total.to_s + ","
|
55
|
+
|
56
|
+
parsed << "Average Price,"
|
57
|
+
|
58
|
+
parsed << average.to_s
|
59
|
+
|
60
|
+
return parsed
|
61
|
+
|
10
62
|
end
|
11
63
|
|
12
64
|
end
|