Class: Proj::Unit

Inherits:
Object
  • Object
show all
Defined in:
lib/proj/unit.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(auth_name, code, name, category, conv_factor, proj_short_name, deprecated) ⇒ Unit

Create a new Unit

Parameters:

  • auth_name (String)

    Authority name

  • code (String)

    Object code

  • name (String)

    Object name. For example “metre”, “US survey foot”, etc

  • category (String)

    Category of the unit: one of “linear”, “linear_per_time”, “angular”, “angular_per_time”, “scale”, “scale_per_time” or “time”

  • conv_factor (String)

    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

  • proj_short_name (String)

    PROJ short name, like “m”, “ft”, “us-ft”, etc… Might be nil

  • deprecated (Boolean)

    Whether the object is deprecated



36
37
38
39
40
41
42
43
44
# File 'lib/proj/unit.rb', line 36

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_nameString (readonly)

Returns Authority name.

Returns:

  • (String)

    Authority name



17
18
19
# File 'lib/proj/unit.rb', line 17

def auth_name
  @auth_name
end

#categoryString (readonly)

Returns Category of the unit: one of “linear”, “linear_per_time”, “angular”, “angular_per_time”, “scale”, “scale_per_time” or “time”.

Returns:

  • (String)

    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

#codeString (readonly)

Returns Object code.

Returns:

  • (String)

    Object code



17
# File 'lib/proj/unit.rb', line 17

attr_reader :auth_name, :code, :name, :category, :conv_factor, :proj_short_name, :deprecated

#conv_factorString (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.

Returns:

  • (String)

    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

#deprecatedObject (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

#nameString (readonly)

Returns Object name. For example “metre”, “US survey foot”, etc.

Returns:

  • (String)

    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_nameString (readonly)

Returns PROJ short name, like “m”, “ft”, “us-ft”, etc… Might be nil.

Returns:

  • (String)

    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.



20
21
22
23
# File 'lib/proj/unit.rb', line 20

def self.built_in(auth_name: nil, category: nil, allow_deprecated: false)
  database = Database.new(Context.current)
  database.units(auth_name: auth_name, category: category, allow_deprecated: allow_deprecated)
end

Instance Method Details

#<=>(other) ⇒ Object



46
47
48
# File 'lib/proj/unit.rb', line 46

def <=>(other)
  self.name <=> other.name
end

#==(other) ⇒ Object



50
51
52
53
# File 'lib/proj/unit.rb', line 50

def ==(other)
  self.auth_name == other.auth_name &&
  self.code == other.code
end

#inspectObject



78
79
80
# File 'lib/proj/unit.rb', line 78

def inspect
  "#<#{self.class} authority=\"#{auth_name}\", code=\"#{code}\", name=\"#{name}\">"
end

#to_sObject



74
75
76
# File 'lib/proj/unit.rb', line 74

def to_s
  self.name
end

#unit_typeObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/proj/unit.rb', line 55

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