class NSWTopo::Layer
Constants
- TYPES
Attributes
name[R]
params[R]
to_s[R]
Public Class Methods
new(name, map, params)
click to toggle source
# File lib/nswtopo/layer.rb, line 20 def initialize(name, map, params) @type = begin NSWTopo.const_get params["type"] rescue NameError, TypeError end raise "unrecognised layer type: %s" % params["type"].inspect unless TYPES === @type extend @type @params = @type.const_defined?(:DEFAULTS) ? @type.const_get(:DEFAULTS).transform_keys(&:to_s).merge(params) : params @name, @map, @source, @path, @resolution = Layer.sanitise(name), map, @params.delete("source"), @params.delete("path"), @params.delete("resolution") @type.const_get(:CREATE).map(&:to_s).each do |attr| instance_variable_set ?@ + attr.tr_s(?-, ?_), @params.delete(attr) end if @type.const_defined?(:CREATE) end
sanitise(name)
click to toggle source
# File lib/nswtopo/layer.rb, line 74 def self.sanitise(name) name&.tr_s '^_a-zA-Z0-9*\-', ?. end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/nswtopo/layer.rb, line 57 def <=>(other) [self, other].map(&:level).inject(&:<=>) end
==(other)
click to toggle source
# File lib/nswtopo/layer.rb, line 61 def ==(other) Layer === other && self.name == other.name end
level()
click to toggle source
# File lib/nswtopo/layer.rb, line 40 def level case when Vegetation == @type then 0 when Import == @type then 1 when ArcGISRaster == @type then 1 when Feature == @type then 2 when Contour == @type then 2 when Spot == @type then 2 when Overlay == @type then 3 when Relief == @type then 4 when Grid == @type then 5 when Declination == @type then 6 when Control == @type then 7 when Labels == @type then 99 end end
pair()
click to toggle source
# File lib/nswtopo/layer.rb, line 70 def pair return name, params end
uptodate?()
click to toggle source
# File lib/nswtopo/layer.rb, line 65 def uptodate? mtimes = [@source&.mtime, @map.mtime(filename)] mtimes.all? && mtimes.inject(&:<) end