davidrichards-just_enumerable_stats 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -97,7 +97,49 @@ Another interesting feature is the default block getter and setter. Sometimes I
97
97
  # => [2,4,6]
98
98
  a.std
99
99
  # => 2.0 instead of 1.0
100
-
100
+
101
+ == Categories
102
+
103
+ Once I started using this gem with my distribution table classes, I needed to have flexible categories on an enumerable. What that looks like is:
104
+
105
+ Loading Just Enumerable Stats version: 0.0.4
106
+ >> a = [1,2,3]
107
+ => [1, 2, 3]
108
+ >> a.categories
109
+ => [1, 2, 3]
110
+ >> a.category_values
111
+ => {1=>[1], 2=>[2], 3=>[3]}
112
+ >> a.set_range_class FixedRange, 1, 3, 0.5
113
+ => FixedRange
114
+ >> a.categories
115
+ => [1.0, 1.5, 2.0, 2.5, 3.0]
116
+ >> a.category_values(true)
117
+ => {1.0=>[1], 1.5=>[], 2.0=>[2], 2.5=>[], 3.0=>[3]}
118
+ >> a.set_range({
119
+ ?> "<3" => lambda{|e| e < 3},
120
+ ?> "3" => lambda{|e| e == 3}
121
+ >> })
122
+ => ["<3", "3"]
123
+ >> a.categories
124
+ => ["<3", "3"]
125
+ >> a.category_values(true)
126
+ => {"<3"=>[1, 2], "3"=>[3]}
127
+ >> a.count_if {|e| e < 3}
128
+ => 2
129
+ >> a.count_if {|e| e == 3}
130
+ => 1
131
+
132
+ OK, here we go:
133
+
134
+ * If you have facets installed (sudo gem install facets), it will use a Dictionary instead of a Hash, keeping the order of the hash values consistent with the order they were loaded. It's nice to have an ordered hash, so go ahead and install that.
135
+ * The categories default as all the unique values in the enumerable
136
+ * category_values is a hash or dictionary of values for each category. The values are returned as an array. This is cached, so call it like a.category_values(true) to reset the hash.
137
+ * set_range_class sets an arbitrary class to use for calculating a range. It should respond to map that will return an array of all values in the range. The arguments after FixedRange are the arguments I want to use when instantiating the class. This is an arbitrary list as well. I could just as easily have typed a.set_range_class FixedRange, a.min, a.max, 0.5 with similar results.
138
+ * FixedRange is a Range that can work with floating numbers. Range.new(1.0, 3.0).map chokes but FixedRange.new(1.0, 3.0).map does not.
139
+ * set_range takes an arbitrary hash of lambdas and sets the categories to the keys of that hash.
140
+ * 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
+ * count_if is just like a.select_all{|e| e < 3}.size, but a little more obvious.
142
+
101
143
  ==Installation
102
144
 
103
145
  sudo gem install davidrichards-just_enumerable_stats
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 0
4
- :patch: 4
4
+ :patch: 5
@@ -1,3 +1,5 @@
1
+ require 'rubygems'
2
+
1
3
  # Need the FixedRange
2
4
  $:.unshift File.dirname(__FILE__)
3
5
  require 'fixed_range'
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.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Richards
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-08-03 00:00:00 -07:00
12
+ date: 2009-08-04 00:00:00 -07:00
13
13
  default_executable: jes
14
14
  dependencies: []
15
15