guidestar 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -34,10 +34,10 @@ Or you can create a Guidestar::Client object and go from there:
34
34
 
35
35
  There are four main API methods that you can use:
36
36
 
37
- Guidestar.search # this is the only tested method on this repo
38
- Guidestar.detailed_search
39
- Guidestar.charity_check
40
- Guidestar.npo_validation
37
+ Guidestar.search # tested
38
+ Guidestar.detailed_search # tested
39
+ Guidestar.charity_check # untested
40
+ Guidestar.npo_validation # untested
41
41
 
42
42
  See https://gsservices.guidestar.org/GuideStar_SearchService/WebServiceSearchQuery.xsd
43
43
  for detailed search parameters.
@@ -4,7 +4,7 @@ module Guidestar
4
4
  include Enumerable
5
5
  extend Forwardable
6
6
 
7
- def_delegators :organizations, :size, :length, :last
7
+ def_delegators :all, :size, :length, :last
8
8
  def_delegators :data, :xml, :total_count, :search_time, :total_pages
9
9
 
10
10
  def initialize(path, client)
@@ -18,11 +18,12 @@ module Guidestar
18
18
  # are new parameters on the request.
19
19
  #
20
20
  # Returns an Array of organizations from the search
21
- def organizations
21
+ def all
22
22
  return @organizations if @organizations
23
23
  load_response
24
24
  @organizations
25
25
  end
26
+ alias :organizations :all
26
27
 
27
28
  # Internal: Contains a few extra details that might be desired, like
28
29
  # the total_count and search_time, which are also available via
@@ -57,20 +58,33 @@ module Guidestar
57
58
 
58
59
  orgs = [orgs] unless orgs.is_a?(Array)
59
60
  orgs.each do |org|
60
- org = Hashie::Mash.new clean_keys(org)
61
+ org = Hashie::Mash.new clean_result(org)
61
62
 
62
- org.delete(:general_information).each do |k,v|
63
+ general_information = org.delete(:general_information) || {}
64
+ general_information.each do |k,v|
63
65
  org[k]=v
64
66
  end
65
- org.delete(:mission_and_programs).each do |type, content|
67
+ mission_and_programs = org.delete(:mission_and_programs) || {}
68
+ mission_and_programs.each do |type, content|
66
69
  content = Nokogiri::HTML content
67
70
  content = content.text.encode(*encoding_options).strip
68
71
  org[type] = content unless content == 'No information currently in database.'
69
72
  end
73
+ ntees = org.delete(:ntees)
74
+ if ntees
75
+ org.ntees = {}
76
+ ntees[:ntee].each do |ntee|
77
+ org.ntees[ntee.code] = ntee.description unless ntee.code.nil?
78
+ end
79
+ end
80
+
81
+ org[:world_locations] = org.delete(:world_locations).to_s.split(', ') if org[:word_locations]
82
+ org[:us_locations] = org.delete(:us_locations).to_s.split(', ') if org[:us_locations]
70
83
 
71
84
  org[:name] = org.delete :org_name
72
85
  org[:tax_deductible] = org[:deductibility] == 'Contributions are deductible, as provided by law'
73
- org[:result_position] = org[:result_position].to_i
86
+ org[:type] = org[:irs_subsection].split(' ').first.gsub(/\W/,'').to_sym if org[:irs_subsection]
87
+ org["is_#{org[:type]}"] = true if org[:type]
74
88
 
75
89
  org[:ein] = EIN.new org[:ein]
76
90
 
@@ -78,14 +92,20 @@ module Guidestar
78
92
  end
79
93
  end
80
94
 
81
- def clean_keys(value)
95
+ def clean_result(value)
82
96
  case value
83
97
  when Array
84
- value.map { |v| clean_keys v }
98
+ value.map { |v| clean_result v }
85
99
  when Hash
86
- Hash[value.map { |k, v| [k.gsub(/(.)([A-Z])/,'\1_\2').downcase.to_sym, clean_keys(v)] }]
100
+ Hash[value.map { |k, v| [k.gsub(/(.)([A-Z])/,'\1_\2').downcase.to_sym, clean_result(v)] }]
87
101
  else
88
- value.nil? ? nil : value.strip
102
+ if value.nil?
103
+ nil
104
+ elsif value =~ /\A[0-9]+\Z/
105
+ value.to_i
106
+ else
107
+ value.strip
108
+ end
89
109
  end
90
110
  end
91
111
 
@@ -1,3 +1,3 @@
1
1
  module Guidestar
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guidestar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-06 00:00:00.000000000 Z
12
+ date: 2013-02-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday