Class: FeatureCode
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- FeatureCode
- Defined in:
- lib/has_geo_lookup/models/feature_code.rb
Overview
Feature classification codes for geographic places from Geonames.org
This model stores the feature classification system used by Geonames.org to categorize different types of geographic features. Each feature code belongs to a feature class and provides detailed categorization for places, administrative divisions, hydrographic features, terrain features, etc.
Feature classes include:
- A: Administrative divisions (countries, states, counties)
- P: Populated places (cities, towns, villages)
- H: Hydrographic features (rivers, lakes, seas)
- T: Terrain features (mountains, hills, valleys)
- R: Roads and railways
- S: Spots and buildings (schools, churches, stations)
- U: Undersea features
- V: Vegetation features (forests, parks)
- L: Localities and areas
Instance Attribute Summary collapse
-
#description ⇒ String
Detailed description of what this feature represents.
-
#feature_class ⇒ String
Single letter feature class (A, P, H, T, R, S, U, V, L).
-
#feature_code ⇒ String
Specific feature code (e.g., PPL, ADM1, RIV, MT).
-
#name ⇒ String
Human-readable name of the feature type.
Class Method Summary collapse
-
.admin_levels ⇒ Array<FeatureCode>
Get all administrative division levels.
-
.find_by_keyword(keyword) ⇒ FeatureCode?
Find the most appropriate feature code for a keyword.
-
.search(keyword) ⇒ ActiveRecord::Relation
Find feature codes matching a search term.
Instance Method Summary collapse
-
#admin_level ⇒ Integer?
Get the administrative level for administrative features.
-
#administrative? ⇒ Boolean
Check if this represents an administrative division.
-
#display_name ⇒ String
Returns a human-readable description.
-
#full_code ⇒ String
Returns the full feature identifier.
-
#hydrographic? ⇒ Boolean
Check if this represents a hydrographic feature.
-
#populated_place? ⇒ Boolean
Check if this represents a populated place.
-
#terrain? ⇒ Boolean
Check if this represents a terrain feature.
Instance Attribute Details
#description ⇒ String
Detailed description of what this feature represents
33 34 35 |
# File 'lib/has_geo_lookup/models/feature_code.rb', line 33 def description @description end |
#feature_class ⇒ String
Single letter feature class (A, P, H, T, R, S, U, V, L)
33 34 35 |
# File 'lib/has_geo_lookup/models/feature_code.rb', line 33 def feature_class @feature_class end |
#feature_code ⇒ String
Specific feature code (e.g., PPL, ADM1, RIV, MT)
33 34 35 |
# File 'lib/has_geo_lookup/models/feature_code.rb', line 33 def feature_code @feature_code end |
#name ⇒ String
Human-readable name of the feature type
33 34 35 |
# File 'lib/has_geo_lookup/models/feature_code.rb', line 33 def name @name end |
Class Method Details
.admin_levels ⇒ Array<FeatureCode>
Get all administrative division levels
Returns all ADM (administrative) feature codes ordered by level, useful for understanding the administrative hierarchy.
97 98 99 |
# File 'lib/has_geo_lookup/models/feature_code.rb', line 97 def self.admin_levels administrative_levels.to_a end |
.find_by_keyword(keyword) ⇒ FeatureCode?
Find the most appropriate feature code for a keyword
Returns the first feature code that matches the keyword, prioritizing exact name matches over description matches.
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/has_geo_lookup/models/feature_code.rb', line 112 def self.find_by_keyword(keyword) return nil if keyword.blank? # First try exact name match exact_match = where("LOWER(name) = ?", keyword.to_s.downcase).first return exact_match if exact_match # Then try partial matches by_keyword(keyword).first end |
.search(keyword) ⇒ ActiveRecord::Relation
Find feature codes matching a search term
Searches both the name and description fields for the given keyword, useful for finding appropriate feature codes when you know the type of place but not the exact code.
83 84 85 |
# File 'lib/has_geo_lookup/models/feature_code.rb', line 83 def self.search(keyword) by_keyword(keyword) end |
Instance Method Details
#admin_level ⇒ Integer?
Get the administrative level for administrative features
179 180 181 182 183 184 |
# File 'lib/has_geo_lookup/models/feature_code.rb', line 179 def admin_level return nil unless administrative? && feature_code.start_with?("ADM") level_match = feature_code.match(/ADM(\d)/) level_match ? level_match[1].to_i : nil end |
#administrative? ⇒ Boolean
Check if this represents an administrative division
155 156 157 |
# File 'lib/has_geo_lookup/models/feature_code.rb', line 155 def administrative? feature_class == "A" end |
#display_name ⇒ String
Returns a human-readable description
Combines the name and description with the feature code for comprehensive identification.
149 150 151 |
# File 'lib/has_geo_lookup/models/feature_code.rb', line 149 def display_name "#{feature_code} - #{name}" end |
#full_code ⇒ String
Returns the full feature identifier
Combines feature class and feature code into a single identifier string for display or logging purposes.
135 136 137 |
# File 'lib/has_geo_lookup/models/feature_code.rb', line 135 def full_code "#{feature_class}.#{feature_code}" end |
#hydrographic? ⇒ Boolean
Check if this represents a hydrographic feature
167 168 169 |
# File 'lib/has_geo_lookup/models/feature_code.rb', line 167 def hydrographic? feature_class == "H" end |
#populated_place? ⇒ Boolean
Check if this represents a populated place
161 162 163 |
# File 'lib/has_geo_lookup/models/feature_code.rb', line 161 def populated_place? feature_class == "P" end |
#terrain? ⇒ Boolean
Check if this represents a terrain feature
173 174 175 |
# File 'lib/has_geo_lookup/models/feature_code.rb', line 173 def terrain? feature_class == "T" end |