Sha256: 2cbf499c363309648262c1f63532fa12d3259c1a3cf5eefedcf7f4903d2915f3

Contents?: true

Size: 737 Bytes

Versions: 1

Compression:

Stored size: 737 Bytes

Contents

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

  def self.find_all_by_autonomous_region_id(autonomous_region_id)
    return [] if autonomous_region_id.blank?

    collection_klass.records.select{ |province| province.autonomous_region_id == autonomous_region_id }
  end

  def places
    INE::Places::Place.find_all_by_province_id(self.id)
  end

  private

  def self.collection_klass
    INE::Places::ProvincesCollection
  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.autonomous_region.slug }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ine-places-0.1.0 lib/ine/places/province.rb