Class: NSWTopo::Layer
- Inherits:
-
Object
- Object
- NSWTopo::Layer
- Defined in:
- lib/nswtopo/layer.rb
Constant Summary collapse
- TYPES =
Set[Vegetation, Import, ColourMask, ArcGISRaster, Feature, Contour, Spot, Overlay, Relief, Grid, Declination, Control, Labels]
Instance Attribute Summary collapse
-
#name ⇒ Object
(also: #to_s)
readonly
Returns the value of attribute name.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
-
#initialize(name, map, params) ⇒ Layer
constructor
A new instance of Layer.
- #level ⇒ Object
- #pair ⇒ Object
- #uptodate? ⇒ Boolean
Constructor Details
#initialize(name, map, params) ⇒ Layer
Returns a new instance of Layer.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/nswtopo/layer.rb', line 25 def initialize(name, map, params) params.delete("min-version").then do |creator_string| creator_string ? Version[creator_string] : VERSION rescue Version::Error raise "layer '%s' has unrecognised version: %s" % [name, creator_string] end.then do |min_version| raise "layer '%s' requires nswtopo %s, this version: %s" % [name, min_version, VERSION] unless min_version <= VERSION end @type = begin NSWTopo.const_get params["type"] rescue NameError, TypeError end raise "layer '%s' has unrecognised type: %s" % [name, params["type"].inspect] unless TYPES === @type extend @type @params = @type.const_defined?(:DEFAULTS) ? @type.const_get(:DEFAULTS).transform_keys(&:to_s).deep_merge(params) : params @name, @map, @source, @path, resolution, ppi = Layer.sanitise(name), map, @params.delete("source"), @params.delete("path"), @params.delete("resolution"), @params.delete("ppi") @mm_per_px = ppi ? 25.4 / ppi : resolution ? @map.to_mm(resolution) : nil @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 |
Instance Attribute Details
#name ⇒ Object (readonly) Also known as: to_s
Returns the value of attribute name.
51 52 53 |
# File 'lib/nswtopo/layer.rb', line 51 def name @name end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
51 52 53 |
# File 'lib/nswtopo/layer.rb', line 51 def params @params end |
Class Method Details
.sanitise(name) ⇒ Object
89 90 91 |
# File 'lib/nswtopo/layer.rb', line 89 def self.sanitise(name) name&.tr_s '^_a-zA-Z0-9*\-', ?. end |
Instance Method Details
#<=>(other) ⇒ Object
72 73 74 |
# File 'lib/nswtopo/layer.rb', line 72 def <=>(other) self.level <=> other.level end |
#==(other) ⇒ Object
76 77 78 |
# File 'lib/nswtopo/layer.rb', line 76 def ==(other) Layer === other && self.name == other.name end |
#level ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/nswtopo/layer.rb', line 54 def level case when Import == @type then 0 when ArcGISRaster == @type then 0 when Vegetation == @type then 1 when ColourMask == @type then 2 when Feature == @type then 3 when Contour == @type then 3 when Spot == @type then 3 when Overlay == @type then 4 when Relief == @type then 5 when Grid == @type then 6 when Declination == @type then 7 when Control == @type then 8 when Labels == @type then 99 end end |
#pair ⇒ Object
85 86 87 |
# File 'lib/nswtopo/layer.rb', line 85 def pair return name, params end |
#uptodate? ⇒ Boolean
80 81 82 83 |
# File 'lib/nswtopo/layer.rb', line 80 def uptodate? mtimes = [@source&.mtime, @map.mtime(filename)] mtimes.all? && mtimes.inject(&:<) end |