fdist 0.2.5 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/fdist.gemspec +2 -2
- data/lib/fdist.rb +12 -76
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6aeede544638ecf3c21966d06b8f487907fe3d8c
|
4
|
+
data.tar.gz: 5da33101451107fa8c63cf05d750dae08fa88620
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a2440896eb82a525eb6ee350297817ca3672273584b20445962e0c8811e14efc921956b6211a792dffba222d44586f71a76bfac9d52bdc23e92fe172d9a5861
|
7
|
+
data.tar.gz: 51d0013862246d3268ca378ec9c21d54482ee0c4b6a8468d1838de05e8bb744539d5b77ef9f74a7313330295672305410d1cedd7d76c679757d8a81068d665d7
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
1.0.0
|
data/fdist.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "fdist"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "1.0.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["michael d. towle"]
|
12
|
-
s.date = "2013-12-
|
12
|
+
s.date = "2013-12-16"
|
13
13
|
s.description = "Array methods now include :freq and :fdist, the first of which returns a Rational, and the second of which returns a hash of expression => count pairs"
|
14
14
|
s.email = "gametheoretic@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/fdist.rb
CHANGED
@@ -1,83 +1,19 @@
|
|
1
|
-
require 'mathn'
|
2
1
|
|
3
|
-
module
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
nil
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def headers= param_list
|
14
|
-
if first.class != Hash
|
15
|
-
if first.class != String
|
16
|
-
map! do |val_set|
|
17
|
-
|
18
|
-
|
19
|
-
hash = {}
|
20
|
-
val_set.each_with_index do |elem, idx|
|
21
|
-
hash[param_list[idx += 1]] = elem
|
22
|
-
end
|
23
|
-
hash
|
24
|
-
end
|
25
|
-
else
|
26
|
-
map! do |val_set|
|
27
|
-
|
28
|
-
|
29
|
-
hash = {}
|
30
|
-
arrayify(val_set).each_with_index do |elem, idx|
|
31
|
-
hash[param_list[idx += 1]] = elem
|
32
|
-
end
|
33
|
-
hash
|
34
|
-
end
|
2
|
+
module Enumerable
|
3
|
+
def set_headers param_list
|
4
|
+
map! do |arr|
|
5
|
+
param_list.zip(arr).inject({}) do |result,zipped|
|
6
|
+
result[zipped.first] = zipped.last
|
7
|
+
result
|
35
8
|
end
|
36
9
|
end
|
37
|
-
map! do |val_hash|
|
38
|
-
redo_headers(val_hash, param_list)
|
39
|
-
end
|
40
|
-
param_list
|
41
|
-
end
|
42
|
-
|
43
|
-
private
|
44
|
-
|
45
|
-
def redo_headers old_hash, new_headers
|
46
|
-
new_hash = {}
|
47
|
-
new_headers.each_with_index do |new_header,idx|
|
48
|
-
new_hash[new_header] = old_hash.values[idx]
|
49
|
-
end
|
50
|
-
new_hash
|
51
10
|
end
|
52
11
|
|
53
|
-
def
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
12
|
+
def fdist &block
|
13
|
+
temp = self.map &block
|
14
|
+
temp.inject({}) do |result,element|
|
15
|
+
result[element] = temp.count element
|
16
|
+
result
|
58
17
|
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
|
63
|
-
module Frequency
|
64
|
-
|
65
|
-
def freq &expression
|
66
|
-
Rational.instance_eval("#{count(&expression)}/#{length}")
|
67
|
-
end
|
68
|
-
|
69
|
-
def fdist
|
70
|
-
memo = {}
|
71
|
-
uniq.sort_by{|x| count(x)}.each do |x|
|
72
|
-
memo[x] = count(x)
|
73
|
-
end
|
74
|
-
memo
|
75
|
-
end
|
76
|
-
|
77
|
-
|
78
|
-
end
|
79
|
-
|
80
|
-
class Array
|
81
|
-
include Frequency
|
82
|
-
include Headers
|
18
|
+
end
|
83
19
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fdist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- michael d. towle
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|