@@ -32,25 +32,27 @@ def rdf_label
3232 return rdf_ons_label unless geonames?
3333
3434 @label = super
35- @label = Array ( "#{ @label . first } County" ) if us_county? && no_county_label
3635
36+ fetch
3737 unless valid_label
3838 return @label if top_level_element?
3939
4040 @label = @label . first
41+ # If this is a county to begin with, it needs it's own suffix
42+ @label = "#{ @label } County" if us_county? ( self )
43+
44+ # For each parent:
45+ # Combine all the labels at this level
46+ # Append the correct ordinal of County if this parent is a US county
47+ # Append the parent to the previous parent/child
4148 parent_hierarchy . each do |p |
42- p . each do |loc |
43- @label = "#{ @label } >> #{ loc . rdf_label . first } "
49+ loc_label = p . map { |loc | loc . rdf_label . first } . sort . join ( '/' )
50+ if us_county? ( p . first )
51+ county_label = p . count > 1 ? 'Counties' : 'County'
52+ loc_label = "#{ loc_label } #{ county_label } "
4453 end
54+ @label = "#{ @label } >> #{ loc_label } "
4555 end
46- # Get all county names
47- counties = @label . split ( '>>' ) . select { |c | c . include? ' County' } . sort . map ( &:strip )
48- # Sort and Combine county names + append "County/Counties"
49- counties = counties . join ( '/' ) . gsub ( ' County' , '' ) + ' County' . pluralize ( counties . count )
50- # Pad the county string
51- counties = " #{ counties . strip } "
52- # Replace old counties with new county string and squash down to one whole string
53- @label = @label . split ( '>>' ) . map { |c | c . include? ( ' County' ) ? counties : c } . uniq . join ( '>>' ) . strip
5456 end
5557 Array ( @label )
5658 end
@@ -132,13 +134,11 @@ def persist!
132134
133135 private
134136
135- # Identify if this is a county in the USA
136- def us_county?
137- feature_code = featureCode . first
138- parent_country = parentCountry . first
137+ # Identify if loc is a county in the USA
138+ def us_county? ( loc )
139139 sec_adm_level_code = 'www.geonames.org/ontology#A.ADM2'
140140 us_country_code = 'sws.geonames.org/6252001/'
141- feature_code . respond_to? ( :rdf_subject ) && feature_code . rdf_subject . to_s . include? ( sec_adm_level_code ) && parent_country . respond_to? ( :rdf_subject ) && parent_country . rdf_subject . to_s . include? ( us_country_code )
141+ loc . featureCode . first & .rdf_subject . to_s . include? ( sec_adm_level_code ) && parentCountry . first & .rdf_subject . to_s . include? ( us_country_code )
142142 end
143143
144144 def no_county_label
0 commit comments