Sha256: 718641983d33e6d9ef08fa0b48b8d5aa8c5ed336b61d5925aa35dd38559e8a8a

Contents?: true

Size: 1.23 KB

Versions: 53

Compression:

Stored size: 1.23 KB

Contents

require 'pathname'

module Spider; module DataTypes
    
    class FilePath < ::Pathname
        include DataType
        maps_to String
        
        take_attributes :base_path, :uploadable
        
        def self.from_value(value)
            return nil if value.to_s.empty?
            super
        end
        
        def map(mapper_type)
            val = nil
            if attributes[:base_path]
                begin
                    val = self.relative_path_from(Pathname.new(attributes[:base_path]))
                rescue ArgumentError
                    val = self
                end
            else
                val = self
            end
            val.to_s
        end
        
        def prepare
            if attributes[:base_path]
                self.new(Pathname.new(attributes[:base_path]) + self)
            else
                self
            end
        end
        
        def format(format_type = :normal)
            return super unless attributes[:base_path]
            if format_type == :long || format_type == :full
                self.to_s
            else
                self.relative_path_from(Pathname.new(attributes[:base_path])).to_s
            end
        end
        
        
    end
    
end; end

Version data entries

53 entries across 53 versions & 1 rubygems

Version Path
spiderfw-1.0.1 lib/spiderfw/model/datatypes/file_path.rb
spiderfw-1.0.0 lib/spiderfw/model/datatypes/file_path.rb
spiderfw-0.6.39 lib/spiderfw/model/datatypes/file_path.rb
spiderfw-0.6.38 lib/spiderfw/model/datatypes/file_path.rb
spiderfw-0.6.37 lib/spiderfw/model/datatypes/file_path.rb
spiderfw-0.6.35 lib/spiderfw/model/datatypes/file_path.rb
spiderfw-0.6.34 lib/spiderfw/model/datatypes/file_path.rb
spiderfw-0.6.33 lib/spiderfw/model/datatypes/file_path.rb
spiderfw-0.6.32 lib/spiderfw/model/datatypes/file_path.rb
spiderfw-0.6.31 lib/spiderfw/model/datatypes/file_path.rb
spiderfw-0.6.30 lib/spiderfw/model/datatypes/file_path.rb
spiderfw-0.6.29 lib/spiderfw/model/datatypes/file_path.rb
spiderfw-0.6.28 lib/spiderfw/model/datatypes/file_path.rb
spiderfw-0.6.27 lib/spiderfw/model/datatypes/file_path.rb
spiderfw-0.6.26 lib/spiderfw/model/datatypes/file_path.rb
spiderfw-0.6.26.pre1 lib/spiderfw/model/datatypes/file_path.rb
spiderfw-0.6.25 lib/spiderfw/model/datatypes/file_path.rb
spiderfw-0.6.24 lib/spiderfw/model/datatypes/file_path.rb
spiderfw-0.6.23 lib/spiderfw/model/datatypes/file_path.rb
spiderfw-0.6.22 lib/spiderfw/model/datatypes/file_path.rb