its_a_map 0.0.1
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.
- data/.gitignore +17 -0
- data/.travis.yml +10 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +95 -0
- data/Rakefile +1 -0
- data/its_a_map.gemspec +26 -0
- data/lib/its_a_map.rb +2 -0
- data/lib/its_a_map/active_support.rb +1 -0
- data/lib/its_a_map/active_support/associative_array.rb +4 -0
- data/lib/its_a_map/active_support/dictionary.rb +4 -0
- data/lib/its_a_map/active_support/map.rb +4 -0
- data/lib/its_a_map/associative_array.rb +6 -0
- data/lib/its_a_map/dictionary.rb +7 -0
- data/lib/its_a_map/map.rb +7 -0
- data/lib/its_a_map/version.rb +3 -0
- data/run_tests.sh +7 -0
- data/spec/its_a_dictionary_spec.rb +17 -0
- data/spec/its_a_map_spec.rb +17 -0
- data/spec/its_an_associative_array_spec.rb +17 -0
- metadata +87 -0
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Hannes Tydén
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
# ItsAMap
|
2
|
+
|
3
|
+

|
4
|
+
|
5
|
+
>> A beloved child has many names.
|
6
|
+
|
7
|
+
[Swedish proverb](http://en.wikiquote.org/wiki/Swedish_proverbs#K)
|
8
|
+
|
9
|
+
What Ruby calls `Hash` is actually a map, a dictionary or an associative array.
|
10
|
+
|
11
|
+
A hash is something different:
|
12
|
+
|
13
|
+
>> A hash function is any algorithm or subroutine that maps large data sets of variable length to smaller data sets of a fixed length.
|
14
|
+
>> [...]
|
15
|
+
>> The values returned by a hash function are called hash values, hash codes, hash sums, checksums or simply hashes.
|
16
|
+
|
17
|
+
[Hash function](http://en.wikipedia.org/wiki/Hash_function)
|
18
|
+
|
19
|
+
I assume the name comes from "hash map" or "hash table", but that's an implementation detail and I don't care about that.
|
20
|
+
|
21
|
+
This library allows you to call maps, dictionaries or associative array by their actual name.
|
22
|
+
|
23
|
+
## Installation
|
24
|
+
|
25
|
+
Add this line to your application's Gemfile:
|
26
|
+
|
27
|
+
gem 'its_a_map'
|
28
|
+
|
29
|
+
And then execute:
|
30
|
+
|
31
|
+
$ bundle
|
32
|
+
|
33
|
+
Or install it yourself as:
|
34
|
+
|
35
|
+
$ gem install its_a_map
|
36
|
+
|
37
|
+
## Usage
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
require 'its_a_map'
|
41
|
+
|
42
|
+
{}.class # => Map
|
43
|
+
# but still
|
44
|
+
Hash === {} # => true
|
45
|
+
```
|
46
|
+
|
47
|
+
or if you're really a pythonista or cocoahead
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
require 'its_a_map/dictionary'
|
51
|
+
|
52
|
+
{}.class # => Dictionary
|
53
|
+
# but still
|
54
|
+
Hash === {} # => true
|
55
|
+
```
|
56
|
+
|
57
|
+
or if you're a PHPer or CS pedantic
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
require 'its_a_map/associative_array'
|
61
|
+
|
62
|
+
{}.class # => AssociativeArray
|
63
|
+
# but still
|
64
|
+
Hash === {} # => true
|
65
|
+
```
|
66
|
+
|
67
|
+
### With `ActiveSupport`
|
68
|
+
|
69
|
+
In case you want to use it in combination with `ActiveSupport`s `HashWithIndifferentAccess`:
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
require 'activesupport/hash_with_indifferent_access'
|
73
|
+
require 'its_a_map/active_support'
|
74
|
+
|
75
|
+
hwia = ActiveSupport::HashWithIndifferentAccess.new({})
|
76
|
+
hwia.class # => ActiveSupport::MapWithIndifferentAccess
|
77
|
+
# but still
|
78
|
+
mwia = ActiveSupport::MapWithIndifferentAccess.new({})
|
79
|
+
ActiveSupport::HashWithIndifferentAccess === mwia # => true
|
80
|
+
```
|
81
|
+
|
82
|
+
You can also
|
83
|
+
`require 'its_a_map/active_support/map'`,
|
84
|
+
`require 'its_a_map/active_support/dictionary'`, or
|
85
|
+
`require 'its_a_map/active_support/associative_array'`.
|
86
|
+
|
87
|
+
Enjoy!
|
88
|
+
|
89
|
+
## Contributing
|
90
|
+
|
91
|
+
1. Fork it
|
92
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
93
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
94
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
95
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/its_a_map.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
require 'its_a_map/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = 'its_a_map'
|
7
|
+
gem.version = ItsAMap::VERSION
|
8
|
+
gem.authors = [ 'Hannes Tydén' ]
|
9
|
+
gem.email = [ 'hannes@tyden.name' ]
|
10
|
+
gem.homepage = 'http://github.com/hannestyden/its_a_map'
|
11
|
+
gem.summary = 'Call it by its real name.'
|
12
|
+
|
13
|
+
gem.description = <<-DESCRIPTION
|
14
|
+
What Ruby calls `Hash` is actually a map, a dictionary or an associative array.
|
15
|
+
DESCRIPTION
|
16
|
+
|
17
|
+
gem.files = `git ls-files`.split("\n")
|
18
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
|
20
|
+
gem.executables =
|
21
|
+
`git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
22
|
+
|
23
|
+
gem.require_paths = [ 'lib' ]
|
24
|
+
|
25
|
+
gem.add_dependency('minitest', '~> 4.4')
|
26
|
+
end
|
data/lib/its_a_map.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.expand_path('../active_support/map', __FILE__)
|
data/run_tests.sh
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'minitest/spec'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
|
4
|
+
$:.push File.expand_path('../../lib', __FILE__)
|
5
|
+
require 'its_a_map/dictionary'
|
6
|
+
|
7
|
+
describe 'ItsAMap' do
|
8
|
+
subject { {}.class }
|
9
|
+
|
10
|
+
it 'should map Hash to Dictionary' do
|
11
|
+
subject.must_equal Dictionary
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should rename Hash to Dictionary' do
|
15
|
+
subject.name.must_equal 'Dictionary'
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'minitest/spec'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
|
4
|
+
$:.push File.expand_path('../../lib', __FILE__)
|
5
|
+
require 'its_a_map'
|
6
|
+
|
7
|
+
describe 'ItsAMap' do
|
8
|
+
subject { {}.class }
|
9
|
+
|
10
|
+
it 'should map Hash to Map' do
|
11
|
+
subject.must_equal Map
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should rename Hash to Map' do
|
15
|
+
subject.name.must_equal 'Map'
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'minitest/spec'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
|
4
|
+
$:.push File.expand_path('../../lib', __FILE__)
|
5
|
+
require 'its_a_map/associative_array'
|
6
|
+
|
7
|
+
describe 'ItsAMap' do
|
8
|
+
subject { {}.class }
|
9
|
+
|
10
|
+
it 'should map Hash to AssociativeArray' do
|
11
|
+
subject.must_equal AssociativeArray
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should rename Hash to AssociativeArray' do
|
15
|
+
subject.name.must_equal 'AssociativeArray'
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: its_a_map
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Hannes Tydén
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: minitest
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '4.4'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '4.4'
|
30
|
+
description: ! ' What Ruby calls `Hash` is actually a map, a dictionary or an associative
|
31
|
+
array.
|
32
|
+
|
33
|
+
'
|
34
|
+
email:
|
35
|
+
- hannes@tyden.name
|
36
|
+
executables: []
|
37
|
+
extensions: []
|
38
|
+
extra_rdoc_files: []
|
39
|
+
files:
|
40
|
+
- .gitignore
|
41
|
+
- .travis.yml
|
42
|
+
- Gemfile
|
43
|
+
- LICENSE.txt
|
44
|
+
- README.md
|
45
|
+
- Rakefile
|
46
|
+
- its_a_map.gemspec
|
47
|
+
- lib/its_a_map.rb
|
48
|
+
- lib/its_a_map/active_support.rb
|
49
|
+
- lib/its_a_map/active_support/associative_array.rb
|
50
|
+
- lib/its_a_map/active_support/dictionary.rb
|
51
|
+
- lib/its_a_map/active_support/map.rb
|
52
|
+
- lib/its_a_map/associative_array.rb
|
53
|
+
- lib/its_a_map/dictionary.rb
|
54
|
+
- lib/its_a_map/map.rb
|
55
|
+
- lib/its_a_map/version.rb
|
56
|
+
- run_tests.sh
|
57
|
+
- spec/its_a_dictionary_spec.rb
|
58
|
+
- spec/its_a_map_spec.rb
|
59
|
+
- spec/its_an_associative_array_spec.rb
|
60
|
+
homepage: http://github.com/hannestyden/its_a_map
|
61
|
+
licenses: []
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 1.8.25
|
81
|
+
signing_key:
|
82
|
+
specification_version: 3
|
83
|
+
summary: Call it by its real name.
|
84
|
+
test_files:
|
85
|
+
- spec/its_a_dictionary_spec.rb
|
86
|
+
- spec/its_a_map_spec.rb
|
87
|
+
- spec/its_an_associative_array_spec.rb
|