Sha256: 8ba225d6a1376d1a4aaf2da79cdc804cadae3d6c8037fe4570cf91b4c850be64

Contents?: true

Size: 566 Bytes

Versions: 1

Compression:

Stored size: 566 Bytes

Contents

module Indirizzo
  class City
    def self.city_parts(city)
      strings = []
      city.map do |string|
        tokens = string.split(" ")
        strings |= (0...tokens.length).to_a.reverse.map do |i|
                   (i...tokens.length).map {|j| tokens[i..j].join(" ")}
        end.flatten
      end
      # Don't return strings that consist solely of abbreviations.
      # NOTE: Is this a micro-optimization that has edge cases that will break?
      # Answer: Yes, it breaks on "Prairie"
      strings.reject { |s| Std_Abbr.key?(s) }.uniq
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
HornsAndHooves-indirizzo-0.1.7.1 lib/indirizzo/city.rb