Sha256: 7c1920f20d6271c23153a48f01e1eb96efba5244981d241aab1d03f8beecc06f

Contents?: true

Size: 545 Bytes

Versions: 3

Compression:

Stored size: 545 Bytes

Contents

# frozen_string_literal: true

class SiteMaps::Adapters::FileSystem::Location < Struct.new(:root, :url)
  ROOT_RE = %r{^/}
  GZIP_RE = %r{\.gz$}

  def path
    File.join(
      root,
      make_relative(uri.path)
    )
  end

  def directory
    Pathname.new(root).join(remote_relative_dir).to_s
  end

  def gzip?
    GZIP_RE.match?(uri.path)
  end

  private

  def uri
    @uri ||= URI.parse(url)
  end

  def remote_relative_dir
    make_relative(File.dirname(uri.path))
  end

  def make_relative(path)
    path.sub(ROOT_RE, "")
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
site_maps-0.0.1.beta3 lib/site_maps/adapters/file_system/location.rb
site_maps-0.0.1.beta2 lib/site_maps/adapters/file_system/location.rb
site_maps-0.0.1.beta1 lib/site_maps/adapters/file_system/location.rb