Sha256: 704ae753360064873e6f481344f6128b784f89307993396f203db63582ee44f6

Contents?: true

Size: 911 Bytes

Versions: 7

Compression:

Stored size: 911 Bytes

Contents

class INE::Places::Place < OpenStruct
  include INE::Places::CSVRecord

  def self.find_all_by_province_id(province_id)
    raise ArgumentError if province_id.blank?

    collection_klass.records.select{ |place| place.province_id == province_id }
  end

  def self.find_by_name_and_province_id(place_name, province_id)
    raise ArgumentError if place_name.blank? || province_id.blank?

    collection_klass.records.select{ |place| place.name == place_name && place.province_id == province_id.to_s }.first
  end

  def data
    @data ||= OpenStruct.new
  end

  private

  def self.collection_klass
    INE::Places::PlacesCollection
  end

  def self.filter(records, name)
    return [] if name.blank?
    parameterized_name = name.parameterize

    records.select{|p| p.slug.include?(parameterized_name) }.
      reject{|p| ['ceuta','melilla'].include?(p.slug) }.
      sort_by{|p| p.province.slug }
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ine-places-0.6.1 lib/ine/places/place.rb
ine-places-0.6.0 lib/ine/places/place.rb
ine-places-0.5.0 lib/ine/places/place.rb
ine-places-0.4.0 lib/ine/places/place.rb
ine-places-0.3.0 lib/ine/places/place.rb
ine-places-0.2.0 lib/ine/places/place.rb
ine-places-0.1.7 lib/ine/places/place.rb