binneroc 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: d70ff7c6d7bfa6b7f32f6a2fa5f685f8ac1b53d5
4
- data.tar.gz: f52335a79ed002f66961a5652198ff6a58c841db
3
+ metadata.gz: a9fe2157dc493e9885a14535c3ee6fe7bee9a7db
4
+ data.tar.gz: 2fc6387c6b1eef1f8d6bb488ac0a73ab68b02b75
5
5
  SHA512:
6
- metadata.gz: b81eaa4e1c4b1236690e091b263efe898299dd226b247f98f205cc1c5131d07c48eb37f7bce8fefee504ad46a2297a54fe2a39c2738ec345cdd470ae8a8add5a
7
- data.tar.gz: 327fae84a3591fedf8f0938f3e7f13cca1a5fe9b06767b36583efe890000158f2939d8a5a31bb0f088c3392da0c988d210acdea2274a6fcdba0585b5ff020d69
6
+ metadata.gz: 57564f23f0fb39f27276cdc1cc3f8a5d9b63bb74ede8fab75eba0504a696239f75c7de14ce2051f26bfe1ea2cfcca6fe9dbd813e388c7fef16e60af8ddf69560
7
+ data.tar.gz: a9b521af7b742b4a7333dba09323b301a12ceb32b71a392d1c61372417f61e427a9f4714bf081f4d5e0c047574499ff1db529543283ef2d740429f221d5f1ca4
data/lib/binneroc.rb CHANGED
@@ -1,6 +1,12 @@
1
1
  require "binneroc/version"
2
2
  require 'bigdecimal'
3
3
 
4
+ if RUBY_VERSION == '2.1.0'
5
+ STDERR.puts "You are using a version of ruby with a known bug in BigDecimal division."
6
+ STDERR.puts "This is fixed in newer versions of ruby. Please upgrade"
7
+ raise
8
+ end
9
+
4
10
  module Binneroc
5
11
 
6
12
  class << self
@@ -54,11 +60,11 @@ module Binneroc
54
60
  #
55
61
  # outputclass needs to be able to create a new vector like object with the
56
62
  # arguments outputclass.new(size, value) or outputclass.new(size).
57
- def bin(xvals, yvals, start: nil, stop: nil, increment: 1.0, default: 0.0, behavior: :sum, outputclass: Array, return_xvals: true, exclude_end: false, consider_default: false)
63
+ def bin(xvals, yvals, start: nil, stop: nil, increment: 1.0, default: 0.0, behavior: :sum, outputclass: Array, return_xvals: true, exclude_end: false, consider_default: false, only_xvals: false)
58
64
  raise ArgumentError, "xvals and yvals need to be parallel (same size)!" unless xvals.size == yvals.size
59
65
 
60
66
  if xvals.size == 0
61
- if return_xvals
67
+ if return_xvals && !only_xvals
62
68
  return [[],[]]
63
69
  else
64
70
  return []
@@ -90,6 +96,13 @@ module Binneroc
90
96
  newsize = array_size(startbd, stopbd, incrementbd, exclude_end)
91
97
  range = Range.new(startbd, startbd + (incrementbd * newsize), exclude_end)
92
98
 
99
+ if return_xvals
100
+ basic_xvals = range.step(incrementbd).to_a
101
+ basic_xvals.pop if basic_xvals.size > newsize
102
+ new_xvals = outputclass.new(basic_xvals)
103
+ end
104
+ return new_xvals if only_xvals
105
+
93
106
  yvec_new = outputclass.new(newsize, default)
94
107
  index_bounds = (0...newsize)
95
108
 
@@ -115,9 +128,7 @@ module Binneroc
115
128
  end
116
129
 
117
130
  if return_xvals
118
- new_xvals = range.step(incrementbd).to_a
119
- new_xvals.pop if new_xvals.size > newsize
120
- [outputclass.new(new_xvals), yvec_new]
131
+ [new_xvals, yvec_new]
121
132
  else
122
133
  yvec_new
123
134
  end
@@ -131,6 +142,11 @@ module Binneroc
131
142
  array_size_floor.to_i
132
143
  end
133
144
 
145
+ # takes the x array and the arguments and produces the xvals that would be
146
+ # produced with bin
147
+ def xvals(xvals, **args)
148
+ end
149
+
134
150
  end
135
151
  end
136
152
 
@@ -1,3 +1,3 @@
1
1
  module Binneroc
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -95,4 +95,8 @@ describe 'iconic case' do
95
95
  expect(reply).to eq [30.0, 30.0, 40.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 50.0]
96
96
  end
97
97
 
98
+ specify 'can return only the x values' do
99
+ reply = Binneroc.bin(*vals, start: "4.0", stop: "5.0", increment: "0.1", only_xvals: true)
100
+ expect(reply).to eq (4..5).step(0.1).to_a
101
+ end
98
102
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: binneroc
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
  - John T. Prince