goldmine 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +5 -0
- data/Gemfile.lock +16 -0
- data/README.md +3 -0
- data/Rakefile +10 -0
- data/lib/goldmine.rb +61 -0
- metadata +53 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/README.md
ADDED
data/Rakefile
ADDED
data/lib/goldmine.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
|
3
|
+
module Goldmine
|
4
|
+
module ArrayMiner
|
5
|
+
def dig(name=nil, &block)
|
6
|
+
reduce({}) do |memo, item|
|
7
|
+
value = yield(item)
|
8
|
+
|
9
|
+
if value.is_a?(Array)
|
10
|
+
if value.empty?
|
11
|
+
memo.assign_mined(name, nil, item)
|
12
|
+
else
|
13
|
+
value.each { |v| memo.assign_mined(name, v, item) }
|
14
|
+
end
|
15
|
+
else
|
16
|
+
memo.assign_mined(name, value, item)
|
17
|
+
end
|
18
|
+
|
19
|
+
memo.goldmine = true
|
20
|
+
memo
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
module HashMiner
|
26
|
+
attr_accessor :goldmine
|
27
|
+
def dig(name=nil, &block)
|
28
|
+
return self unless goldmined
|
29
|
+
reduce({}) do |memo, item|
|
30
|
+
key = item.first
|
31
|
+
value = item.last
|
32
|
+
value.mine(name, &block).each do |k, v|
|
33
|
+
new_key = []
|
34
|
+
if key.is_a? Array
|
35
|
+
new_key = new_key + key
|
36
|
+
else
|
37
|
+
new_key << key
|
38
|
+
end
|
39
|
+
new_key << k
|
40
|
+
memo[new_key] = v
|
41
|
+
end
|
42
|
+
memo.goldmine = true
|
43
|
+
memo
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def assign_mined(name, key, value)
|
48
|
+
mine_key = goldmine_key(name, key)
|
49
|
+
self[mine_key] ||= []
|
50
|
+
self[goldmine_key(name, key)] << value
|
51
|
+
end
|
52
|
+
|
53
|
+
def goldmine_key(name, key)
|
54
|
+
mine_key = "#{name}: #{key}" if name
|
55
|
+
mine_key ||= key
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
::Array.send(:include, Goldmine::ArrayMiner)
|
61
|
+
::Hash.send(:include, Goldmine::HashMiner)
|
metadata
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: goldmine
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Nathan Hopkins
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-19 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: ! ' ...
|
15
|
+
|
16
|
+
'
|
17
|
+
email:
|
18
|
+
- natehop@gmail.com
|
19
|
+
executables: []
|
20
|
+
extensions: []
|
21
|
+
extra_rdoc_files: []
|
22
|
+
files:
|
23
|
+
- lib/goldmine.rb
|
24
|
+
- Gemfile
|
25
|
+
- Gemfile.lock
|
26
|
+
- Rakefile
|
27
|
+
- README.md
|
28
|
+
homepage: https://github.com/hopsoft/goldmine
|
29
|
+
licenses:
|
30
|
+
- MIT
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
requirements: []
|
48
|
+
rubyforge_project:
|
49
|
+
rubygems_version: 1.8.10
|
50
|
+
signing_key:
|
51
|
+
specification_version: 3
|
52
|
+
summary: Powerful data mining for lists of objects.
|
53
|
+
test_files: []
|