Sha256: 787aa7b67467961e5dc1de9a63d0421d4d54e6b0d077f3138308df80f653675f

Contents?: true

Size: 892 Bytes

Versions: 12

Compression:

Stored size: 892 Bytes

Contents

module SmallCage
  class DocumentPath
    
    attr_reader :root, :uri, :path
    
    def initialize(root, path)
      @root = Pathname.new(root).realpath;

      @path = Pathname.new(path)
      if @path.exist?
        @path = @path.realpath
      else
        @path = @path.cleanpath
      end
      
      if @path.to_s[0...@root.to_s.length] != @root.to_s
        raise "Illegal path: #{path.to_s}"
      end
      
      if @path == @root
        @uri = "/"
      else
        @uri = @path.to_s[@root.to_s.length .. -1]
      end
    end
    
    def smc?
      return @path.extname == ".smc"
    end
    
    def outfile
      return nil unless smc?
      return self.class.new(@root, @path.to_s[0 .. -5])
    end
    
    def outuri
      return nil unless smc?
      return uri[0 .. -5]
    end

    def self.to_uri(root, path)
      return self.new(root,path).uri
    end

  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
bluemark-smallcage-0.1.3 lib/smallcage/document_path.rb
bluemark-smallcage-0.1.4 lib/smallcage/document_path.rb
bluemark-smallcage-0.1.5 lib/smallcage/document_path.rb
smallcage-0.1.7 lib/smallcage/document_path.rb
smallcage-0.1.6 lib/smallcage/document_path.rb
smallcage-0.1.5 lib/smallcage/document_path.rb
smallcage-0.1.4 lib/smallcage/document_path.rb
smallcage-0.1.3 lib/smallcage/document_path.rb
smallcage-0.1.0 lib/smallcage/document_path.rb
smallcage-0.1.1 lib/smallcage/document_path.rb
smallcage-0.1.2 lib/smallcage/document_path.rb
smallcage-0.0.9 lib/smallcage/document_path.rb