mycoins 0.3.4 → 0.3.5

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: 81094f6de11121c276fa8bd1039820aec9783736
4
- data.tar.gz: 2396fe1349594814d82360abe4ba713820dbb93f
3
+ metadata.gz: bd59d18937ce9fc62449408978b57aa3d7a099f2
4
+ data.tar.gz: 7f180dd3ed3f2a909abfacf039e56c17957d954a
5
5
  SHA512:
6
- metadata.gz: 6c616ce1a054d8cf5bab8b38af96bfb715e19555ffc0daefbb2877ff3d3ceb174584b258d75b88dde2b5c4a0e1a0f6350f82a7e514dda9bbf3c2cf62db1d15ef
7
- data.tar.gz: bf1a81b0e3c4f1d8e1637062e40a5405478209e655da423f0ea09e6dc9e01781498f60ee182d57609d3cd372de49efa13defeea82d92ff9c81c53f90568ec648
6
+ metadata.gz: 396925dc7f5288544eb79dc0ec5f964322624f7c82e77e4ded10ca5b20086c8343805468c404c614d674e8a33fe9730f2e94efc77f4da4691f12735c91936957
7
+ data.tar.gz: c45831af7f6479299ba68a5709a8c35cc1405937d0e171bfc0865cc894d0c07d548c6718abe18e66168be6bc477f534d45bd44a103dccc2e24bc5a4f7d590b9e
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -14,7 +14,7 @@ class MyCoins
14
14
  def initialize(source, date: nil, debug: false,
15
15
  mycurrency: 'USD', filepath: 'mycoins', colored: true)
16
16
 
17
- @debug, @filepath, @color = debug, filepath, colored
17
+ @debug, @filepath, @colored = debug, filepath, colored
18
18
 
19
19
  @jer = JustExchangeRates.new(base: 'USD')
20
20
 
@@ -69,6 +69,45 @@ class MyCoins
69
69
  File.write filepath, to_xml
70
70
 
71
71
  end
72
+
73
+ def to_dx()
74
+
75
+ r = build_portfolio(@dx.title)
76
+ dx = Dynarex.new
77
+ dx.import r.records
78
+
79
+ h = r.to_h
80
+ h.delete :records
81
+ dx.summary.merge!(h)
82
+
83
+ dx
84
+
85
+ end
86
+
87
+ def to_openstruct()
88
+ build_portfolio(@dx.title)
89
+ end
90
+
91
+ def to_percentages()
92
+
93
+ all = self.to_dx.to_a
94
+ val = ('value_' + @mycurrency.downcase).to_sym
95
+
96
+ a = all.map {|x| x[val].to_f }
97
+ sum = a.inject(&:+)
98
+
99
+ a2 = all.map do |x|
100
+ [x[:title].sub(/\s+\[[^\]]\]+/,''), (x[val].to_f).round(2)]
101
+ end.group_by(&:first).to_a
102
+
103
+ a3 = a2.map do |x|
104
+ [x.first, ((x[1].inject(0) {|r,y| r + y[1].to_f} / sum.to_f) * 100)\
105
+ .round(2)]
106
+ end
107
+
108
+ a3.sort_by(&:last).reverse.to_h
109
+
110
+ end
72
111
 
73
112
  def to_s()
74
113
  @ccf.to_s
@@ -99,15 +138,7 @@ class MyCoins
99
138
 
100
139
  def to_xml()
101
140
 
102
- r = build_portfolio(@dx.title)
103
- dx = Dynarex.new
104
- dx.import r.records
105
-
106
- h = r.to_h
107
- h.delete :records
108
- dx.summary.merge!(h)
109
-
110
- dx.to_xml pretty: true
141
+ self.to_dx().to_xml pretty: true
111
142
 
112
143
  end
113
144
 
@@ -153,7 +184,7 @@ class MyCoins
153
184
  pct_gross_profit: pct_gross_profit,
154
185
  pct_losses: pct_losses,
155
186
  net_profit: sum(a, :roi).round(2),
156
- pct_net_profit: pct_gross_profit + pct_losses
187
+ pct_net_profit: (pct_gross_profit + pct_losses).round(2)
157
188
  }
158
189
 
159
190
  @portfolio = OpenStruct.new(h)
@@ -284,7 +315,7 @@ class MyCoins
284
315
  [c(r.gross_profit), @mycurrency, c(r.pct_gross_profit.to_s + "%")]
285
316
  out << "\nLosses: %.2f %s (%.2f%%)" % [r.losses, @mycurrency, r.pct_losses]
286
317
  out << "\n\nNet profit: %s %s (%s)" % [c(r.net_profit), @mycurrency,
287
- c(r.pct_net_profit.to_s + "%")]
318
+ c(r.pct_net_profit.to_s + "%")]
288
319
  out << "\nCurrent value: %.2f %s (%s BTC)" % [r.value, @mycurrency,
289
320
  r.btc_value]
290
321
  out
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mycoins
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -30,7 +30,7 @@ cert_chain:
30
30
  sCz5KsiHA9vj8OfrxhYrEb+ML4+J28Umdki7V1vgnQWmnI+Ok2SWlkScgzcmGXF6
31
31
  TJ4=
32
32
  -----END CERTIFICATE-----
33
- date: 2018-03-10 00:00:00.000000000 Z
33
+ date: 2018-04-30 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: dynarex
metadata.gz.sig CHANGED
Binary file