Class: Proj::Unit
- Inherits:
-
Object
- Object
- Proj::Unit
- Defined in:
- lib/proj/unit.rb
Instance Attribute Summary collapse
-
#auth_name ⇒ String
readonly
Authority name.
-
#category ⇒ String
readonly
Category of the unit: one of “linear”, “linear_per_time”, “angular”, “angular_per_time”, “scale”, “scale_per_time” or “time”.
-
#code ⇒ String
readonly
Object code.
-
#conv_factor ⇒ String
readonly
Conversion factor to apply to transform from that unit to the corresponding SI unit (metre for “linear”, radian for “angular”, etc.).
-
#deprecated ⇒ Object
readonly
Returns the value of attribute deprecated.
-
#name ⇒ String
readonly
Object name.
-
#proj_short_name ⇒ String
readonly
PROJ short name, like “m”, “ft”, “us-ft”, etc…
Class Method Summary collapse
-
.built_in(auth_name: nil, category: nil, allow_deprecated: false) ⇒ Object
Returns a list of built in Units.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
-
#initialize(auth_name, code, name, category, conv_factor, proj_short_name, deprecated) ⇒ Unit
constructor
Create a new Unit.
- #inspect ⇒ Object
- #to_s ⇒ Object
- #unit_type ⇒ Object
Constructor Details
#initialize(auth_name, code, name, category, conv_factor, proj_short_name, deprecated) ⇒ Unit
Create a new Unit
63 64 65 66 67 68 69 70 71 |
# File 'lib/proj/unit.rb', line 63 def initialize(auth_name, code, name, category, conv_factor, proj_short_name, deprecated) @auth_name = auth_name @code = code @name = name @category = category @conv_factor = conv_factor @proj_short_name = proj_short_name @deprecated = deprecated end |
Instance Attribute Details
#auth_name ⇒ String (readonly)
Returns Authority name.
17 18 19 |
# File 'lib/proj/unit.rb', line 17 def auth_name @auth_name end |
#category ⇒ String (readonly)
Returns Category of the unit: one of “linear”, “linear_per_time”, “angular”, “angular_per_time”, “scale”, “scale_per_time” or “time”.
17 |
# File 'lib/proj/unit.rb', line 17 attr_reader :auth_name, :code, :name, :category, :conv_factor, :proj_short_name, :deprecated |
#code ⇒ String (readonly)
Returns Object code.
17 |
# File 'lib/proj/unit.rb', line 17 attr_reader :auth_name, :code, :name, :category, :conv_factor, :proj_short_name, :deprecated |
#conv_factor ⇒ String (readonly)
Returns Conversion factor to apply to transform from that unit to the corresponding SI unit (metre for “linear”, radian for “angular”, etc.). It might be 0 in some cases to indicate no known conversion factor.
17 |
# File 'lib/proj/unit.rb', line 17 attr_reader :auth_name, :code, :name, :category, :conv_factor, :proj_short_name, :deprecated |
#deprecated ⇒ Object (readonly)
Returns the value of attribute deprecated.
17 |
# File 'lib/proj/unit.rb', line 17 attr_reader :auth_name, :code, :name, :category, :conv_factor, :proj_short_name, :deprecated |
#name ⇒ String (readonly)
Returns Object name. For example “metre”, “US survey foot”, etc.
17 |
# File 'lib/proj/unit.rb', line 17 attr_reader :auth_name, :code, :name, :category, :conv_factor, :proj_short_name, :deprecated |
#proj_short_name ⇒ String (readonly)
Returns PROJ short name, like “m”, “ft”, “us-ft”, etc… Might be nil.
17 |
# File 'lib/proj/unit.rb', line 17 attr_reader :auth_name, :code, :name, :category, :conv_factor, :proj_short_name, :deprecated |
Class Method Details
.built_in(auth_name: nil, category: nil, allow_deprecated: false) ⇒ Object
Returns a list of built in Units. This is deprecated. Use Database#units instead
20 21 22 23 24 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 50 |
# File 'lib/proj/unit.rb', line 20 def self.built_in(auth_name: nil, category: nil, allow_deprecated: false) # First get linear units pointer_to_array = FFI::Pointer.new(Api::PJ_UNITS, Api.proj_list_units) result = Array.new 0.step do |i| unit_info = Api::PJ_UNITS.new(pointer_to_array[i]) break if unit_info[:id].nil? result << self.new('PROJ', unit_info[:id], unit_info[:name], 'length', unit_info[:factor], unit_info[:id], false) end # Now get angular linear units if Api.method_defined?(:proj_list_angular_units) pointer_to_array = FFI::Pointer.new(Api::PJ_UNITS, Api.proj_list_angular_units) 0.step do |i| unit_info = Api::PJ_UNITS.new(pointer_to_array[i]) break result if unit_info[:id].nil? result << self.new('PROJ', unit_info[:id], unit_info[:name], 'angular', unit_info[:factor], unit_info[:id], false) end end if auth_name result = result.find_all {|unit_info| unit_info.auth_name == auth_name} end if category result = result.find_all {|unit_info| unit_info.category == category} end result end |
Instance Method Details
#<=>(other) ⇒ Object
73 74 75 |
# File 'lib/proj/unit.rb', line 73 def <=>(other) self.name <=> other.name end |
#==(other) ⇒ Object
77 78 79 80 |
# File 'lib/proj/unit.rb', line 77 def ==(other) self.auth_name == other.auth_name && self.code == other.code end |
#inspect ⇒ Object
105 106 107 |
# File 'lib/proj/unit.rb', line 105 def inspect "#<#{self.class} authority=\"#{auth_name}\", code=\"#{code}\", name=\"#{name}\">" end |
#to_s ⇒ Object
101 102 103 |
# File 'lib/proj/unit.rb', line 101 def to_s self.name end |
#unit_type ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/proj/unit.rb', line 82 def unit_type case self.category when "linear" :PJ_UT_LINEAR when "linear_per_time" :PJ_UT_LINEAR when "angular" :PJ_UT_ANGULAR when "angular_per_time" :PJ_UT_ANGULAR when "scale" :PJ_UT_SCALE when "scale_per_time" :PJ_UT_SCALE when "time" :PJ_UT_TIME end end |