bet 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 52e7c97a52bb4e4ba5a5dcb2a98f6467225a6718
4
- data.tar.gz: 9b38ee0ad8f170b0bbc0189c4d7f8a2ebefd0141
3
+ metadata.gz: 98a33134f1f23b9347eb046690cc6f2692c6452b
4
+ data.tar.gz: e8a3390c0910bca81f24b078ac295c99c12a0521
5
5
  SHA512:
6
- metadata.gz: 200218acceb2434ecd5c1618e5ad14a12725ed38188855cfae3b20a28b1dde7cb2a7d28547a49cf4a9d04aea574c5e2d394d9251d928c135f1e368bd4ef56596
7
- data.tar.gz: bf770179e639fbe4aa05007f478ac36d150cd83c38a88cea5e422af439dd5dabbcf87430754f7bb01d66e5a9e967a5239ef3d3486d06ad9e21cd17b16a283ddd
6
+ metadata.gz: e32a4970b3ad3570f0cc0121a5d7c316052640feb649fa8b45c49dbcc907e9d606ce4edd319544e17cd1ab417030d2803ab7eb30a06fbd18aa9c719af3d34269
7
+ data.tar.gz: 87c053a6cb75605c10422fb29145c00df682d39ac263398e31de4a38c6e31cb5824531737a9ae7be482381076bb91b6bfd8aac238a221f59918b9415df3d2859
@@ -11,8 +11,8 @@ module Bet
11
11
  block: 9
12
12
  }.each do |ord, n|
13
13
  define_method(ord) do |opts|
14
- prices = extract_prices(opts)
15
- raise ArgumentError, "Wrong number of prices (#{prices.size} for #{n})" if prices.size != n
14
+ results = extract_prices(opts)
15
+ raise ArgumentError, "Wrong number of results (#{results.size} for #{n})" if results.size != n
16
16
  opts[:min_size] = 2
17
17
  full_cover(opts)
18
18
  end
@@ -28,8 +28,8 @@ module Bet
28
28
  block_with_singles: 9
29
29
  }.each do |ord, n|
30
30
  define_method(ord) do |opts|
31
- prices = extract_prices(opts)
32
- raise ArgumentError, "Wrong number of prices (#{prices.size} for #{n})" if prices.size != n
31
+ results = extract_prices(opts)
32
+ raise ArgumentError, "Wrong number of results (#{results.size} for #{n})" if results.size != n
33
33
  full_cover(opts)
34
34
  end
35
35
  end
@@ -39,18 +39,30 @@ module Bet
39
39
  opts = parse_opts(opts)
40
40
  opts = { min_size: 1 }.merge(opts)
41
41
 
42
- num_bets = 0
43
- returns = (opts[:min_size]..opts[:prices].length).to_a.map do |n|
44
- win_prices.combination(n).map do |multis|
45
- num_bets += 1
46
- acca(stake: opts[:stake], prices: multis)
42
+ num_bets = (opts[:min_size]..prices.length).to_a.map do |n|
43
+ (1..prices.length).to_a.combination(n).to_a.length
44
+ end.reduce(:+)
45
+
46
+ winning_prices = if prices.is_a?(Hash)
47
+ prices.select{ |_,v| win_place_lose?(v) == :win }.keys
48
+ else
49
+ prices
50
+ end
51
+
52
+ returns = (opts[:min_size]..winning_prices.length).to_a.map do |n|
53
+ winning_prices.combination(n).map do |multis|
54
+ acca(stake: opts[:stake], prices: multis)[:returns]
47
55
  end.reduce(:+)
48
56
  end.reduce(:+)
49
57
 
50
- total_stake = num_bets * stake
51
- profit = returns - total_stake
58
+ outlay = num_bets * opts[:stake]
59
+ profit = returns - outlay
52
60
 
53
- [returns, profit, total_stake]
61
+ {
62
+ returns: returns,
63
+ profit: profit,
64
+ outlay: outlay
65
+ }
54
66
  end
55
67
  end
56
68
  end
@@ -15,13 +15,17 @@ module Bet
15
15
 
16
16
  return send("ew_#{__method__}") if opts[:ew]
17
17
 
18
- returns = c(opts[:stake], opts[:prices].reduce(:*))
18
+ returns = c(opts[:stake], prices.reduce(:*))
19
19
  profit = returns - opts[:stake]
20
20
 
21
- [returns, profit, opts[:stake]]
21
+ {
22
+ returns: returns,
23
+ profit: profit,
24
+ outlay: opts[:stake]
25
+ }
22
26
  end
23
- alias :acca, :accumulator
24
- alias :parlay, :accumulator
27
+ alias_method :acca, :accumulator
28
+ alias_method :parlay, :accumulator
25
29
  end
26
30
  end
27
31
  end
data/lib/bet/calc.rb CHANGED
@@ -12,34 +12,36 @@ module Bet
12
12
  DEFAULT_OPTS = { stake: 1, ew: false }
13
13
  WIN_PLACE_LOSS_INTEGER = { -1 => :loss, 0 => :place, 1 => :win }
14
14
 
15
- attr_accessor :returns, :profit
15
+ attr_accessor :returns, :profit, :outlay
16
16
 
17
17
  def initialize(bet_type, opts)
18
- @returns, @profit, @stake = send(bet_type, opts)
18
+ @returns, @profit, @outlay = send(bet_type, opts).values
19
19
  end
20
20
 
21
- private
22
- def win_place_lose?(v)
23
- v.is_a?(Fixnum) ? WIN_PLACE_LOSS_INTEGER[v] : v
24
- end
25
-
26
- def c(stake, price)
27
- stake * price
28
- end
29
-
30
- def extract_prices(opts_or_prices)
31
- case opts_or_prices
32
- when Hash
33
- opts_or_prices[:prices]
34
- when Numeric
35
- [opts_or_prices]
36
- else
37
- opts_or_prices
21
+ class << self
22
+ private
23
+ def win_place_lose?(v)
24
+ v.is_a?(Fixnum) ? WIN_PLACE_LOSS_INTEGER[v] : v
38
25
  end
39
- end
40
26
 
41
- def parse_opts(opts_or_prices)
42
- opts_or_prices.is_a?(Hash) ? DEFAULT_OPTS.merge(opts_or_prices) : DEFAULT_OPTS
43
- end
27
+ def c(stake, price)
28
+ stake * price
29
+ end
30
+
31
+ def extract_prices(opts_or_prices)
32
+ case opts_or_prices
33
+ when Hash
34
+ opts_or_prices[:prices] ? extract_prices(opts_or_prices[:prices]) : opts_or_prices
35
+ when Numeric
36
+ [opts_or_prices]
37
+ else
38
+ opts_or_prices
39
+ end
40
+ end
41
+
42
+ def parse_opts(opts_or_prices)
43
+ opts_or_prices.is_a?(Hash) ? DEFAULT_OPTS.merge(opts_or_prices) : DEFAULT_OPTS
44
+ end
45
+ end
44
46
  end
45
47
  end
data/lib/bet/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Bet
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Campbell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-30 00:00:00.000000000 Z
11
+ date: 2015-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler