goldmine 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/Gemfile +5 -0
  2. data/Gemfile.lock +16 -0
  3. data/README.md +3 -0
  4. data/Rakefile +10 -0
  5. data/lib/goldmine.rb +61 -0
  6. metadata +53 -0
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source :rubygems
2
+
3
+ group :development do
4
+ gem "pry"
5
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,16 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ coderay (1.0.6)
5
+ method_source (0.7.1)
6
+ pry (0.9.9.6)
7
+ coderay (~> 1.0.5)
8
+ method_source (~> 0.7.1)
9
+ slop (>= 2.4.4, < 3)
10
+ slop (2.4.4)
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ pry
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Goldmine
2
+
3
+ Docs coming soon...
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ Rake::TestTask.new(:test) do |t|
6
+ t.test_files = FileList['test/*_test.rb']
7
+ end
8
+
9
+ task 'test:units' => ['test'] do
10
+ end
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: []