ntee 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +16 -1
- data/Rakefile +9 -0
- data/lib/ntee.rb +41 -20
- data/lib/ntee/version.rb +1 -1
- data/ntee.gemspec +1 -0
- metadata +36 -18
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 03b80da907998c1501a017b67b3a77157ec8496a62d5a6d2942f588a414f6e20
|
4
|
+
data.tar.gz: 474320909c63ff0c4dadd46a9ab4afeccf6f2af7e96dcc6983a5a640f30fb430
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8e254d86d9376ab2fe718df3d976f72592fcbdd5db26492116513fb38763068dbb1f8e635f618b08f646d5b1aa0e9bfc5a84fb6d4b21d4689f9fb273c431a228
|
7
|
+
data.tar.gz: 7d42be8621df32db7c2a04f444e21edb43be8b044bf36522d17765cfe7c9e4d55bfc2efe60e7566cdbdfecec5a9c2fd3bd3401a987800e79a6496ddbad4a6a20
|
data/README.md
CHANGED
@@ -15,10 +15,25 @@ category.ancestors # [NTEE.category("R60"), NTEE.category("R")]
|
|
15
15
|
|
16
16
|
Easy-peasy!
|
17
17
|
|
18
|
+
There is also a helper method to make this easy to build Rails selection dropdowns
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
NTEE.as_list
|
22
|
+
```
|
23
|
+
|
18
24
|
## search_dimensions integration
|
19
25
|
|
20
26
|
The file `lib/ntee/search_dimension.rb` defines a few classes you can use in conjunction with Gively's `search_dimensions` gem to deal with NTEE categories stored in a Solr search index. `NTEE::HierarchicalDimension` lets you treat the categories as a hierarchical tree, and `NTEE::FlatDimension` lets you treat them as a plain string field.
|
21
27
|
|
22
28
|
## Licensing
|
23
29
|
|
24
|
-
This gem is Copyright © 2011-2012 Gively, Inc. and is released under the MIT license. For more details, please see the LICENSE file.
|
30
|
+
This gem is Copyright © 2011-2012 Gively, Inc. and is released under the MIT license. For more details, please see the LICENSE file.
|
31
|
+
|
32
|
+
## Testing and Debugging
|
33
|
+
|
34
|
+
To test in console
|
35
|
+
|
36
|
+
```shell
|
37
|
+
bundle install
|
38
|
+
bundle exec rake test:console
|
39
|
+
```
|
data/Rakefile
CHANGED
data/lib/ntee.rb
CHANGED
@@ -3,27 +3,31 @@ require 'ntee/version'
|
|
3
3
|
module NTEE
|
4
4
|
class Category
|
5
5
|
attr_accessor :name, :code, :subcategories, :parent
|
6
|
-
|
6
|
+
|
7
7
|
def initialize
|
8
8
|
self.subcategories ||= {}
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
|
+
def to_s
|
12
|
+
"#{name} (#{code})"
|
13
|
+
end
|
14
|
+
|
11
15
|
def inspect
|
12
16
|
"<NTEE Category #{code} (#{name})>"
|
13
17
|
end
|
14
|
-
|
18
|
+
|
15
19
|
def [](subcategory_code)
|
16
20
|
self.subcategories[subcategory_code.to_s]
|
17
21
|
end
|
18
|
-
|
22
|
+
|
19
23
|
def parent=(parent)
|
20
24
|
if parent && parent[code] != self
|
21
|
-
parent.add_subcategory!(self)
|
25
|
+
parent.add_subcategory!(self)
|
22
26
|
end
|
23
|
-
|
27
|
+
|
24
28
|
@parent = parent
|
25
29
|
end
|
26
|
-
|
30
|
+
|
27
31
|
def ancestors
|
28
32
|
if parent
|
29
33
|
[parent] + parent.ancestors
|
@@ -31,28 +35,28 @@ module NTEE
|
|
31
35
|
[]
|
32
36
|
end
|
33
37
|
end
|
34
|
-
|
38
|
+
|
35
39
|
def descendants
|
36
40
|
(subcategories.values + subcategories.values.map(&:descendants)).flatten
|
37
41
|
end
|
38
|
-
|
42
|
+
|
39
43
|
def add_subcategory!(subcategory)
|
40
44
|
subcategories[subcategory.code.to_s] = subcategory
|
41
45
|
subcategory.parent = self
|
42
46
|
subcategories
|
43
47
|
end
|
44
|
-
|
48
|
+
|
45
49
|
def as_json(options={})
|
46
50
|
hsh = {
|
47
51
|
'code' => code,
|
48
52
|
'name' => name
|
49
53
|
}
|
50
|
-
|
54
|
+
|
51
55
|
hsh['subcategories'] = subcategories.values.as_json(options) if subcategories && subcategories.count > 0
|
52
|
-
|
56
|
+
|
53
57
|
hsh
|
54
58
|
end
|
55
|
-
|
59
|
+
|
56
60
|
def attributes=(attributes)
|
57
61
|
attributes.each do |name, value|
|
58
62
|
case name.to_s
|
@@ -73,7 +77,7 @@ module NTEE
|
|
73
77
|
raise "Subcategory #{value.inspect} is neither a Category nor a Hash"
|
74
78
|
end
|
75
79
|
end
|
76
|
-
|
80
|
+
|
77
81
|
subcats.each do |subcat|
|
78
82
|
add_subcategory!(subcat)
|
79
83
|
end
|
@@ -81,10 +85,10 @@ module NTEE
|
|
81
85
|
end
|
82
86
|
end
|
83
87
|
end
|
84
|
-
|
88
|
+
|
85
89
|
class << self
|
86
90
|
attr_accessor :root_categories, :all_categories
|
87
|
-
|
91
|
+
|
88
92
|
def category(cat_or_code)
|
89
93
|
case cat_or_code
|
90
94
|
when NTEE::Category
|
@@ -93,7 +97,7 @@ module NTEE
|
|
93
97
|
all_categories[cat_or_code.to_s]
|
94
98
|
end
|
95
99
|
end
|
96
|
-
|
100
|
+
|
97
101
|
def add_category!(category)
|
98
102
|
root_categories[category.code.to_s] = category if category.parent.nil?
|
99
103
|
category.subcategories.each do |code, subcategory|
|
@@ -102,14 +106,31 @@ module NTEE
|
|
102
106
|
all_categories[category.code.to_s] = category
|
103
107
|
end
|
104
108
|
end
|
105
|
-
|
109
|
+
|
106
110
|
self.root_categories = {}
|
107
111
|
self.all_categories = {}
|
112
|
+
|
113
|
+
def self.as_list
|
114
|
+
@as_list ||= sort_by_code(flattened_categories)
|
115
|
+
end
|
116
|
+
|
117
|
+
private
|
118
|
+
|
119
|
+
def self.flattened_categories
|
120
|
+
all_categories.map do |parent_category|
|
121
|
+
c = parent_category[1]
|
122
|
+
[c.to_s, c.code]
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def self.sort_by_code(arr)
|
127
|
+
arr.sort {|a, b| a[1] <=> b[1] }
|
128
|
+
end
|
108
129
|
end
|
109
130
|
|
110
131
|
begin
|
111
132
|
require 'json'
|
112
|
-
|
133
|
+
|
113
134
|
File.open(File.expand_path("../ntee_categories.json", __FILE__), 'r') do |file|
|
114
135
|
JSON.load(file).each do |attributes|
|
115
136
|
NTEE::Category.new.tap do |category|
|
@@ -121,4 +142,4 @@ begin
|
|
121
142
|
rescue
|
122
143
|
puts "WARNING: Couldn't load NTEE categories!"
|
123
144
|
puts $!
|
124
|
-
end
|
145
|
+
end
|
data/lib/ntee/version.rb
CHANGED
data/ntee.gemspec
CHANGED
metadata
CHANGED
@@ -1,38 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ntee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.4
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Nat Budin
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2018-09-20 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: i18n
|
16
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
25
27
|
- !ruby/object:Gem::Dependency
|
26
28
|
name: activesupport
|
27
|
-
requirement:
|
28
|
-
none: false
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
|
-
- -
|
31
|
+
- - ">="
|
31
32
|
- !ruby/object:Gem::Version
|
32
33
|
version: '3.0'
|
33
34
|
type: :development
|
34
35
|
prerelease: false
|
35
|
-
version_requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
36
55
|
description: Utilities to support the Urban Institute's National Taxonomy of Exempt
|
37
56
|
Entities
|
38
57
|
email:
|
@@ -41,7 +60,7 @@ executables: []
|
|
41
60
|
extensions: []
|
42
61
|
extra_rdoc_files: []
|
43
62
|
files:
|
44
|
-
- .gitignore
|
63
|
+
- ".gitignore"
|
45
64
|
- Gemfile
|
46
65
|
- LICENSE
|
47
66
|
- README.md
|
@@ -53,26 +72,25 @@ files:
|
|
53
72
|
- ntee.gemspec
|
54
73
|
homepage: https://github.com/gively/ntee
|
55
74
|
licenses: []
|
75
|
+
metadata: {}
|
56
76
|
post_install_message:
|
57
77
|
rdoc_options: []
|
58
78
|
require_paths:
|
59
79
|
- lib
|
60
80
|
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
-
none: false
|
62
81
|
requirements:
|
63
|
-
- -
|
82
|
+
- - ">="
|
64
83
|
- !ruby/object:Gem::Version
|
65
84
|
version: '0'
|
66
85
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
-
none: false
|
68
86
|
requirements:
|
69
|
-
- -
|
87
|
+
- - ">="
|
70
88
|
- !ruby/object:Gem::Version
|
71
89
|
version: '0'
|
72
90
|
requirements: []
|
73
91
|
rubyforge_project:
|
74
|
-
rubygems_version:
|
92
|
+
rubygems_version: 2.7.3
|
75
93
|
signing_key:
|
76
|
-
specification_version:
|
94
|
+
specification_version: 4
|
77
95
|
summary: NTEE utilities for US nonprofit entity categorization
|
78
96
|
test_files: []
|