sixarm_ruby_hash_more 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
File without changes
@@ -0,0 +1,121 @@
1
+ # SixArm.com » Ruby » <br> HashMore class for dynamic hashes
2
+
3
+ * Docs: <http://sixarm.com/sixarm_ruby_hash_more/doc>
4
+ * Repo: <http://github.com/sixarm/sixarm_ruby_hash_more>
5
+ * Email: Joel Parker Henderson, <joel@sixarm.com>
6
+
7
+
8
+ ## Introduction
9
+
10
+ HashMore is a hash of hashes of hashes and so on recursively, enabling arbitrarily access (and assignment of values) to specific elements of a (multi-dimensional) hash, whether the element already exists or not.
11
+
12
+ For docs go to <http://sixarm.com/sixarm_ruby_hash_more/doc>
13
+
14
+ Want to help? We're happy to get pull requests.
15
+
16
+
17
+ ## Quickstart
18
+
19
+ Install:
20
+
21
+ gem install sixarm_ruby_hash_more
22
+
23
+ Bundler:
24
+
25
+ gem "sixarm_ruby_hash_more", "=1.3.0"
26
+
27
+ Require:
28
+
29
+ require "sixarm_ruby_hash_more"
30
+
31
+
32
+ ## High Security (Optional)
33
+
34
+ To enable high security for all our gems:
35
+
36
+ wget http://sixarm.com/sixarm.pem
37
+ gem cert --add sixarm.pem
38
+ gem sources --add http://sixarm.com
39
+
40
+ To install with high security:
41
+
42
+ gem install sixarm_ruby_ --test --trust-policy HighSecurity
43
+
44
+
45
+ ## Details
46
+
47
+ Ruby's built-in Hash class will raise an error if code attempts to access an element which doesn't exist; HashMore will create the necessary elements and then execute the access.
48
+
49
+ Additionally, using the += operator to assign a numeric value to an element
50
+
51
+
52
+ ## Examples
53
+
54
+ hash = HashMore.new
55
+ hash["red"]["apple"] = true
56
+ hash["red"]["dress"] = true
57
+ hash["red"]["truck"] = true
58
+ hash["red"] => {"apple"=>true, "dress"=>true, "truck"=>true}
59
+
60
+
61
+ ## Counting and Totals
62
+
63
+ This class is also useful for building aggregate data about a set of similar objects, such as how many employees are in each department of each division of a company or total tax and sale amounts for a set of invoices by customer by year.
64
+
65
+ Counting example:
66
+
67
+ h = HashMore.new
68
+ employees = Employee.all
69
+ for e in employees
70
+ h[e.division][e.department]+=1
71
+ end
72
+
73
+ h['sales']['east coast] => 28
74
+ h['sales']['west coast] => 23
75
+
76
+ Totals example:
77
+
78
+ h = HashMore.new
79
+ invoices = Invoices.all
80
+
81
+ for i in invoices
82
+ h[i.customer.name][i.sale_date.year]['tax'] += i.tax_amount
83
+ h[i.customer.name][i.sale_date.year]['sale'] += i.sale_amount
84
+ end
85
+
86
+ h['Acme Corp']['2008']['tax'] => 12039.12
87
+ h['Acme Corp']['2009']['sale'] => 102649
88
+
89
+
90
+ ## Changes
91
+
92
+ * 2012-03-17 1.3.0 Upgrade for Ruby 1.9.3, minitest/spec, and improved docs.
93
+
94
+
95
+ ## License
96
+
97
+ You may choose any of these open source licenses:
98
+
99
+ * Apache License
100
+ * BSD License
101
+ * CreativeCommons License, Non-commercial Share Alike
102
+ * GNU General Public License Version 2 (GPL 2)
103
+ * GNU Lesser General Public License (LGPL)
104
+ * MIT License
105
+ * Perl Artistic License
106
+ * Ruby License
107
+
108
+ The software is provided "as is", without warranty of any kind,
109
+ express or implied, including but not limited to the warranties of
110
+ merchantability, fitness for a particular purpose and noninfringement.
111
+
112
+ In no event shall the authors or copyright holders be liable for any
113
+ claim, damages or other liability, whether in an action of contract,
114
+ tort or otherwise, arising from, out of or in connection with the
115
+ software or the use or other dealings in the software.
116
+
117
+ This license is for the included software that is created by SixArm;
118
+ some of the included software may have its own licenses, copyrights,
119
+ authors, etc. and these do take precedence over the SixArm license.
120
+
121
+ Copyright (c) 2005-2012 Joel Parker Henderson
@@ -0,0 +1,8 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new(:test) do |t|
6
+ t.libs << 'lib' << 'test'
7
+ t.pattern = 'test/*.rb'
8
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.2.8
@@ -0,0 +1,17 @@
1
+ # -*- coding: utf-8 -*-
2
+ =begin rdoc
3
+ Please see README
4
+ =end
5
+
6
+
7
+ class HashMore < Hash
8
+
9
+ def initialize
10
+ super{|h,k| h[k] = HashMore.new }
11
+ end
12
+
13
+ def +(x)
14
+ x
15
+ end
16
+
17
+ end
@@ -0,0 +1,41 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'minitest/autorun'
3
+ require 'simplecov'
4
+ SimpleCov.start
5
+ require 'sixarm_ruby_hash_more'
6
+
7
+ describe HashMore do
8
+
9
+ before do
10
+ @h = HashMore.new
11
+ end
12
+
13
+ describe ".new" do
14
+
15
+ it "is a blank hash" do
16
+ @h.must_equal Hash.new
17
+ end
18
+
19
+ end
20
+
21
+ describe "=" do
22
+
23
+ it "=" do
24
+ @h[:a][:b][:c] = 'hello'
25
+ @h[:a][:b][:c].must_equal 'hello'
26
+ end
27
+
28
+ end
29
+
30
+ describe "+" do
31
+
32
+ it "+=" do
33
+ @h[:a][:b][:c] += 3
34
+ @h[:a][:b][:c].must_equal 3
35
+ @h[:a][:b][:c] += 3
36
+ @h[:a][:b][:c].must_equal 6
37
+ end
38
+
39
+ end
40
+
41
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sixarm_ruby_hash_more
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.3.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - SixArm
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain:
12
+ - !binary |-
13
+ LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURCRENDQW0yZ0F3SUJB
14
+ Z0lKQUtQd0VFVFU1YkhvTUEwR0NTcUdTSWIzRFFFQkJRVUFNR0F4Q3pBSkJn
15
+ TlYKQkFZVEFsVlRNUk13RVFZRFZRUUlFd3BEWVd4cFptOXlibWxoTVJZd0ZB
16
+ WURWUVFIRXcxVFlXNGdSbk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FmOHdEUVlKS29aSWh2Y05BUUVGQlFB
33
+ RGdZRUFvb0VleFAvb1BhbTFUUDcxU3l1aHhNYit1VHJaYlNRZQpqVkIrRXhS
34
+ d1dhZEd3YU5QVUE1NmQzOXF3YXZ3UCtpdSszSnBlb25OTVZ2YldYRjVuYUNY
35
+ L2RORkllUkVIekVSClpEUlFZTXFydTlURU1uYTZIRDl6cGNzdEY3dndUaEdv
36
+ dmxPUSszWTZwbFE0bk16aXBYY1o5VEhxczY1UElMMHEKZWFid3BDYkFvcG89
37
+ Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K
38
+ date: 2012-03-17 00:00:00.000000000 Z
39
+ dependencies: []
40
+ description:
41
+ email: sixarm@sixarm.com
42
+ executables: []
43
+ extensions: []
44
+ extra_rdoc_files: []
45
+ files:
46
+ - .gemtest
47
+ - Rakefile
48
+ - README.md
49
+ - VERSION
50
+ - lib/sixarm_ruby_hash_more.rb
51
+ - test/sixarm_ruby_hash_more_test.rb
52
+ homepage: http://sixarm.com/
53
+ licenses: []
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubyforge_project:
72
+ rubygems_version: 1.8.11
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: ! 'SixArm Ruby Gem: HashMore class to create a recursive hash'
76
+ test_files:
77
+ - test/sixarm_ruby_hash_more_test.rb
78
+ has_rdoc: true
@@ -0,0 +1,3 @@
1
+ l�fm�R���{,���X�I�IM��Ծ$ᰋa�^�~[ �
2
+ I�ȵ�Y䞮Z:�
3
+ pjw�G�cq�����Z%6�iBp���5,)]7V(�L�,5���c�ѐA-E}NN',���R�~�