Sha256: fa1b1ed3946ded670dc9b344b211f4d99d6fe26bbc545810d2802dcc8683c70e

Contents?: true

Size: 988 Bytes

Versions: 11

Compression:

Stored size: 988 Bytes

Contents

module Vitreous
  module Share
    class LocalStructure < CommonStructure
    
      def initialize( path )
        @path = path
      end
      
      def generate( path = @path )
        {
          'name'     => path == @path ? File.basename( File.dirname( path ) ) : File.basename( path ),
          'path'     => path == @path ? '/' : path.gsub( @path, '' ),
          'uri'      => uri( path ),
          'type'     => File.directory?( path ) ? 'directory' : 'file',
          'elements' => File.directory?( path ) ? tree( path ) : [],
          'content'  => CommonStructure.txt?( path ) ? File.read( path ).force_encoding('utf-8') : nil
        }
      end
      
      def tree( path )
        Dir.glob( File.join( path, '*' ) ).sort.map do |e|
          generate( e ) 
        end
      end
      
      def uri( path )
        "#{Vitreous::Share::LocalStructure.base_uri}#{path.gsub( @path, '' )}"
      end
      
      def self.base_uri
        ""
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
vitreous_share-0.0.31 lib/vitreous/share/local_structure.rb
vitreous_share-0.0.27 lib/vitreous/share/local_structure.rb
vitreous_share-0.0.25 lib/vitreous/share/local_structure.rb
vitreous_share-0.0.23 lib/vitreous/share/local_structure.rb
vitreous_share-0.0.21 lib/vitreous/share/local_structure.rb
vitreous_share-0.0.19 lib/vitreous/share/local_structure.rb
vitreous_share-0.0.17 lib/vitreous/share/local_structure.rb
vitreous_share-0.0.15 lib/vitreous/share/local_structure.rb
vitreous_share-0.0.13 lib/vitreous/share/local_structure.rb
vitreous_share-0.0.11 lib/vitreous/share/local_structure.rb
vitreous_share-0.0.9 lib/vitreous/share/local_structure.rb