sibit 0.35.0 → 0.35.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/sibit/bestof.rb +23 -6
- data/lib/sibit/version.rb +1 -1
- 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: d545c42be046368aee30cdc1baab63944b45c97b8b68b4f9fabe6b44ca036d15
|
|
4
|
+
data.tar.gz: b0dcc6193397326031efdf8089f15682946083f6dac8e221ed8a3f3f18f37abf
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 78728c5d74334bd3c02f07bf6c33139d13f98d01f48ecb81790f5901d27106d10e6e069c5e7a779f3b01df73e22b9c2b7e435f0d5039734ec811b435c1a111c0
|
|
7
|
+
data.tar.gz: 32c68a1e19d52ec99aae38c165d8b501d210315fcd843a789c351c2efbba2516ff69c80efcba022a5ab59edad4ef23a69f668351ba640f32a568b505b9facab2
|
data/lib/sibit/bestof.rb
CHANGED
|
@@ -20,11 +20,12 @@ class Sibit::BestOf
|
|
|
20
20
|
@verbose = verbose
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
-
# Current price of BTC in USD (float returned).
|
|
23
|
+
# Current price of BTC in USD (float returned). Exchanges never quote
|
|
24
|
+
# the exact same number, so this one does not vote: it averages all
|
|
25
|
+
# answers and fails when they are more than five percent apart.
|
|
24
26
|
def price(currency = 'USD')
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
end
|
|
27
|
+
return @list.price(currency) unless @list.is_a?(Array)
|
|
28
|
+
average('price', answers('price') { |api| api.price(currency) })
|
|
28
29
|
end
|
|
29
30
|
|
|
30
31
|
# Gets the balance of the address, in satoshi.
|
|
@@ -97,8 +98,12 @@ class Sibit::BestOf
|
|
|
97
98
|
|
|
98
99
|
private
|
|
99
100
|
|
|
100
|
-
def best_of(method)
|
|
101
|
+
def best_of(method, &blk)
|
|
101
102
|
return yield(@list) unless @list.is_a?(Array)
|
|
103
|
+
majority(method, answers(method, &blk))
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def answers(method)
|
|
102
107
|
votes = []
|
|
103
108
|
errors = []
|
|
104
109
|
@list.each do |api|
|
|
@@ -117,7 +122,19 @@ class Sibit::BestOf
|
|
|
117
122
|
"#{@list.map { |a| a.class.name }.join(', ')}"
|
|
118
123
|
)
|
|
119
124
|
end
|
|
120
|
-
|
|
125
|
+
votes
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def average(method, votes)
|
|
129
|
+
prices = votes.map { |v| v[1] }
|
|
130
|
+
if (prices.max - prices.min) / prices.min > 0.05
|
|
131
|
+
raise(
|
|
132
|
+
Sibit::Error,
|
|
133
|
+
"The answers at #{method}() are more than 5% apart: " \
|
|
134
|
+
"#{votes.map { |name, answer| "#{name}=#{answer}" }.join(', ')}"
|
|
135
|
+
)
|
|
136
|
+
end
|
|
137
|
+
prices.sum / prices.size
|
|
121
138
|
end
|
|
122
139
|
|
|
123
140
|
def majority(method, votes)
|
data/lib/sibit/version.rb
CHANGED