Class: Proj::Grid
- Inherits:
-
Object
- Object
- Proj::Grid
- Defined in:
- lib/proj/grid.rb
Overview
Grids define models that are used to perform dimension shifts.
Grid files can be quite large and may not be included with Proj depending on how it was packaged and any grid licensing requirements. Therefore, Proj has the ability to download grids on the fly if networking is enabled.
Instance Attribute Summary collapse
-
#context ⇒ Context
readonly
The grid context.
-
#full_name ⇒ String
readonly
The grid’s full name.
-
#name ⇒ String
readonly
The grid’s name.
-
#package_name ⇒ String
readonly
The grid’s package name.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#available? ⇒ Boolean
Returns whether the grid is available at runtime.
-
#delete ⇒ Object
Deletes the grid if it has been downloaded.
-
#download(ignore_ttl = false) {|percent| ... } ⇒ Boolean
Download a file in the PROJ user-writable directory if has not already been downlaoded.
-
#downloadable? ⇒ Boolean
Returns whether the grid can be downloaded.
-
#downloaded?(ignore_ttl = false) ⇒ Boolean
Returns if a grid is available in the PROJ user-writable directory.
-
#info ⇒ GridInfo
Returns information about this grid.
-
#initialize(name, context = Context.default, full_name: nil, package_name: nil, url: nil, downloadable: false, open_license: false, available: false) ⇒ Grid
constructor
A new instance of Grid.
-
#open_license? ⇒ Boolean
Returns whether the grid is released with an open license.
-
#path ⇒ String
Returns the path to the grid if it has been downloaded.
Constructor Details
#initialize(name, context = Context.default, full_name: nil, package_name: nil, url: nil, downloadable: false, open_license: false, available: false) ⇒ Grid
Returns a new instance of Grid.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/proj/grid.rb', line 22 def initialize(name, context = Context.default, full_name: nil, package_name: nil, url: nil, downloadable: false, open_license: false, available: false) @name = name @context = context @full_name = full_name @package_name = package_name @url = url @downloadable = downloadable @open_license = open_license @available = available end |
Instance Attribute Details
#context ⇒ Context (readonly)
Returns The grid context.
20 21 22 |
# File 'lib/proj/grid.rb', line 20 def context @context end |
#full_name ⇒ String (readonly)
Returns The grid’s full name.
20 |
# File 'lib/proj/grid.rb', line 20 attr_reader :context, :name, :full_name, :package_name, :url |
#name ⇒ String (readonly)
Returns The grid’s name.
20 |
# File 'lib/proj/grid.rb', line 20 attr_reader :context, :name, :full_name, :package_name, :url |
#package_name ⇒ String (readonly)
Returns The grid’s package name.
20 |
# File 'lib/proj/grid.rb', line 20 attr_reader :context, :name, :full_name, :package_name, :url |
#url ⇒ Object (readonly)
Returns the value of attribute url.
20 |
# File 'lib/proj/grid.rb', line 20 attr_reader :context, :name, :full_name, :package_name, :url |
Instance Method Details
#available? ⇒ Boolean
Returns whether the grid is available at runtime
51 52 53 |
# File 'lib/proj/grid.rb', line 51 def available? @available end |
#delete ⇒ Object
Deletes the grid if it has been downloaded
105 106 107 108 109 110 |
# File 'lib/proj/grid.rb', line 105 def delete if self.downloaded? path = File.join(self.context.user_directory, self.name) File.delete(path) if File.exist?(path) end end |
#download(ignore_ttl = false) {|percent| ... } ⇒ Boolean
Download a file in the PROJ user-writable directory if has not already been downlaoded. This function can only be used if networking is enabled
91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/proj/grid.rb', line 91 def download(ignore_ttl = false) callback = if block_given? Proc.new do |context, percent, user_data| result = yield percent # Return 1 to tell Proj to keep downloading the file result ? 1 : 0 end end result = Api.proj_download_file(self.context, self.url&.to_s || self.name, ignore_ttl ? 1 : 0, callback, nil) result == 1 ? true : false end |
#downloadable? ⇒ Boolean
Returns whether the grid can be downloaded
37 38 39 |
# File 'lib/proj/grid.rb', line 37 def downloadable? @downloadable end |
#downloaded?(ignore_ttl = false) ⇒ Boolean
Returns if a grid is available in the PROJ user-writable directory. This method will only return true if Context#network_enabled? is true
73 74 75 76 77 78 79 80 |
# File 'lib/proj/grid.rb', line 73 def downloaded?(ignore_ttl = false) if self.context.network_enabled? result = Api.proj_is_download_needed(self.context, self.url&.to_s || self.name, ignore_ttl ? 1 : 0) result == 1 ? false : true else false end end |
#info ⇒ GridInfo
Returns information about this grid
See proj.org/development/reference/functions.html#c.proj_grid_info proj_grid_info
60 61 62 63 |
# File 'lib/proj/grid.rb', line 60 def info ptr = Api.proj_grid_info(self.name) GridInfo.new(ptr) end |
#open_license? ⇒ Boolean
Returns whether the grid is released with an open license
44 45 46 |
# File 'lib/proj/grid.rb', line 44 def open_license? @open_license end |
#path ⇒ String
Returns the path to the grid if it has been downloaded
115 116 117 118 119 |
# File 'lib/proj/grid.rb', line 115 def path if self.downloaded? File.join(self.context.user_directory, self.name) end end |