davidrichards-just_enumerable_stats 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -128,6 +128,14 @@ Once I started using this gem with my distribution table classes, I needed to ha
128
128
  => 2
129
129
  >> a.count_if {|e| e == 3}
130
130
  => 1
131
+ >> a.dichotomize(2, :small, :big)
132
+ => [:small, :big]
133
+ >> a.categories
134
+ => [:small, :big]
135
+ >> a.category_values[:small]
136
+ => [1, 2]
137
+ >> a.category_values[:big]
138
+ => [3]
131
139
 
132
140
  OK, here we go:
133
141
 
@@ -139,6 +147,7 @@ OK, here we go:
139
147
  * set_range takes an arbitrary hash of lambdas and sets the categories to the keys of that hash.
140
148
  * The category_values calculated with a hash of lambdas makes a very flexible set interface for enumerables. There is no rule that the categories setup this way have to be mutually exclusive or collectively exhaustive (MECE), so interesting data sets can be setup here. However, MECE is generally a good guideline for most analysis.
141
149
  * count_if is just like a.select_all{|e| e < 3}.size, but a little more obvious.
150
+ * dichotomize just splits the categories into two, with the first category less than or equal to the split value provided (2 in our case)
142
151
 
143
152
  ==Installation
144
153
 
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 0
4
- :patch: 5
4
+ :patch: 6
@@ -270,6 +270,14 @@ module Enumerable
270
270
  # The arguments needed to instantiate the custom-defined range class.
271
271
  attr_reader :range_class_args
272
272
 
273
+ # Splits the values in two, <= the value and > the value.
274
+ def dichotomize(split_value, first_label, second_label)
275
+ set_range({
276
+ first_label => lambda{|e| e <= split_value},
277
+ second_label => lambda{|e| e > split_value}
278
+ })
279
+ end
280
+
273
281
  # Counts each element where the block evaluates to true
274
282
  # Example:
275
283
  # a = [1,2,3]
@@ -257,6 +257,14 @@ module JustEnumerableStats #:nodoc:
257
257
  # The arguments needed to instantiate the custom-defined range class.
258
258
  attr_reader :range_class_args
259
259
 
260
+ # Splits the values in two, <= the value and > the value.
261
+ def dichotomize(split_value, first_label, second_label)
262
+ set_range({
263
+ first_label => lambda{|e| e <= split_value},
264
+ second_label => lambda{|e| e > split_value}
265
+ })
266
+ end
267
+
260
268
  # Counts each element where the block evaluates to true
261
269
  # Example:
262
270
  # a = [1,2,3]
@@ -279,6 +279,13 @@ describe JustEnumerableStats::Stats do
279
279
  @a.count_if {|e| e == 2}.should eql(1)
280
280
  end
281
281
 
282
+ it "should be able to dichotomize a list" do
283
+ @a.dichotomize(2, :small, :big)
284
+ @a.categories.should eql([:small, :big])
285
+ @a.category_values[:small].should eql([1,2])
286
+ @a.category_values[:big].should eql([3])
287
+ end
288
+
282
289
  it "should be able to instantiate a range" do
283
290
  @a.range_as_range.should eql(Range.new(1, 3))
284
291
  end
@@ -269,6 +269,13 @@ describe "JustEnumerableStats" do
269
269
  @a.count_if {|e| e == 2}.should eql(1)
270
270
  end
271
271
 
272
+ it "should be able to dichotomize a list" do
273
+ @a.dichotomize(2, :small, :big)
274
+ @a.categories.should eql([:small, :big])
275
+ @a.category_values[:small].should eql([1,2])
276
+ @a.category_values[:big].should eql([3])
277
+ end
278
+
272
279
  it "should be able to instantiate a range with a block" do
273
280
  @a.range_as_range(&@inverse_matcher).should eql(Range.new(3, 1))
274
281
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: davidrichards-just_enumerable_stats
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Richards