Class: Geonames::Data::Feature
- Inherits:
-
Object
- Object
- Geonames::Data::Feature
- Defined in:
- lib/geonames/data/feature.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data) ⇒ Feature
constructor
A new instance of Feature.
- #names ⇒ Object
Constructor Details
#initialize(data) ⇒ Feature
Returns a new instance of Feature.
41 42 43 |
# File 'lib/geonames/data/feature.rb', line 41 def initialize(data) @data = data.dup end |
Class Method Details
.field(name) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/geonames/data/feature.rb', line 6 def self.field(name) @fields ||= [] index = @fields.size @fields << name if block_given? define_method name do yield(@data[index]) end else define_method name do @data[index] end end end |
.load(filepath, &filter) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/geonames/data/feature.rb', line 49 def self.load(filepath, &filter) Pathname.new(filepath).open("r").inject([]) do |features, line| feature = Feature.new(line.strip.split("\t")) features.push(feature) if !block_given? || yield(feature) features end end |
Instance Method Details
#names ⇒ Object
45 46 47 |
# File 'lib/geonames/data/feature.rb', line 45 def names @names ||= [ name, ascii_name, *alternate_names ] end |