Class: GrassCookbook::Data
- Inherits:
-
Object
- Object
- GrassCookbook::Data
- Defined in:
- lib/grassgis/cookbook.rb
Overview
Datasets used by recipes, consist of parmeters, maps and files (or directories). Recipes use them to define both required and generated data.
Instance Attribute Summary collapse
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#maps ⇒ Object
readonly
Returns the value of attribute maps.
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
Class Method Summary collapse
Instance Method Summary collapse
- #+(other) ⇒ Object
- #-(other) ⇒ Object
- #dup ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(params = {}) ⇒ Data
constructor
A new instance of Data.
- #merge!(data) ⇒ Object
-
#missing(required) ⇒ Object
data which is requiered but not provided here.
- #present? ⇒ Boolean
- #raster_maps ⇒ Object
- #to_s ⇒ Object
- #vector_maps ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Data
Returns a new instance of Data.
104 105 106 107 108 |
# File 'lib/grassgis/cookbook.rb', line 104 def initialize(params = {}) @parameters = params[:parameters] || [] @files = params[:files] || [] @maps = params[:maps] || [] end |
Instance Attribute Details
#files ⇒ Object (readonly)
Returns the value of attribute files.
110 111 112 |
# File 'lib/grassgis/cookbook.rb', line 110 def files @files end |
#maps ⇒ Object (readonly)
Returns the value of attribute maps.
110 111 112 |
# File 'lib/grassgis/cookbook.rb', line 110 def maps @maps end |
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
110 111 112 |
# File 'lib/grassgis/cookbook.rb', line 110 def parameters @parameters end |
Class Method Details
Instance Method Details
#+(other) ⇒ Object
156 157 158 |
# File 'lib/grassgis/cookbook.rb', line 156 def +(other) dup.merge! other end |
#-(other) ⇒ Object
147 148 149 150 151 152 153 154 |
# File 'lib/grassgis/cookbook.rb', line 147 def -(other) other = Data[other] Data[ parameters: parameters - other.parameters, files: files - other.files, maps: maps - other.maps ] end |
#dup ⇒ Object
128 129 130 |
# File 'lib/grassgis/cookbook.rb', line 128 def dup Data.new.merge! self end |
#empty? ⇒ Boolean
143 144 145 |
# File 'lib/grassgis/cookbook.rb', line 143 def empty? !present? end |
#merge!(data) ⇒ Object
120 121 122 123 124 125 126 |
# File 'lib/grassgis/cookbook.rb', line 120 def merge!(data) data = Data[data] @parameters = (@parameters + data.parameters).uniq @maps = (@maps + data.maps).uniq @files = (@files + data.files).uniq self end |
#missing(required) ⇒ Object
data which is requiered but not provided here
161 162 163 |
# File 'lib/grassgis/cookbook.rb', line 161 def missing(required) Data[required] - self end |
#present? ⇒ Boolean
139 140 141 |
# File 'lib/grassgis/cookbook.rb', line 139 def present? @parameters.size > 0 || @files.size > 0 || @maps.size > 0 end |
#raster_maps ⇒ Object
116 117 118 |
# File 'lib/grassgis/cookbook.rb', line 116 def raster_maps @maps.select { |m, t| t == :raster } end |
#to_s ⇒ Object
165 166 167 168 169 170 171 |
# File 'lib/grassgis/cookbook.rb', line 165 def to_s txt = "Datos:\n" txt << " Parametros: #{parameters.inspect}\n" txt << " Archivos: #{files.inspect}\n" txt << " Mapas: #{maps.inspect}\n" txt end |
#vector_maps ⇒ Object
112 113 114 |
# File 'lib/grassgis/cookbook.rb', line 112 def vector_maps @maps.select { |m, t| t == :vector }.map(&:first) end |