Sha256: e41f1f593fc3474ee4e9e8cb9f425e4311821dc0bd3474a739adbbe2248ab24a

Contents?: true

Size: 669 Bytes

Versions: 3

Compression:

Stored size: 669 Bytes

Contents

# frozen_string_literal: true

class SiteMaps::Builder::SitemapIndex::Item < Struct.new(:loc, :lastmod)
  extend Forwardable

  def to_xml
    builder = ::Builder::XmlMarkup.new
    builder.sitemap do
      builder.loc(loc)
      builder.lastmod w3c_date(lastmod) if lastmod
    end
    builder << "\n"
  end

  def eql?(other)
    loc == other.loc
  end
  alias_method :==, :eql?

  def hash
    loc.hash
  end

  def relative_directory
    return unless loc =~ %r{^https?://[^/]+(/.*)$}

    val = File.dirname(Regexp.last_match(1))
    val = val[1..-1] if val.start_with?("/")
    val
  end

  protected

  def_delegator SiteMaps::Builder::Normalizer, :w3c_date
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
site_maps-0.0.1.beta3 lib/site_maps/builder/sitemap_index/item.rb
site_maps-0.0.1.beta2 lib/site_maps/builder/sitemap_index/item.rb
site_maps-0.0.1.beta1 lib/site_maps/builder/sitemap_index/item.rb