Sha256: dbf704141994671c3b8949e504b36315a67ffc7020667abdac87c57ba89cd983

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

module Jekyll
  module Maps
    class LocationFinder
      def initialize(options)
        @documents = []
        @options   = options
      end

      def find(site, page)
        if @options[:flags][:on_page]
          @documents << page if location?(page)
        else
          site.collections.each { |_, collection| filter(collection.docs) }
          site.data.each { |_, docs| filter(docs) }
        end

        @documents.map do |document|
          {
            :latitude  => document["location"]["latitude"],
            :longitude => document["location"]["longitude"],
            :title     => document["title"],
            :url       => document["url"] || document.url
          }
        end
      end

      private
      def filter(docs)
        docs.each do |doc|
          @documents << doc if location?(doc) && match_filters?(doc)
        end
      end

      private
      def location?(doc)
        !doc["location"].nil? && !doc["location"].empty?
      end

      private
      def match_filters?(doc)
        @options[:filters].each do |key, value|
          return false if doc[key].nil? || doc[key] != value
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jekyll-maps-1.1.3 lib/jekyll-maps/location_finder.rb