Class: Proj::Unit

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, to_meter, factor, name) ⇒ Unit

Returns a new instance of Unit.



31
32
33
34
35
36
# File 'lib/unit.rb', line 31

def initialize(id, to_meter, factor, name)
  @id = id
  @to_meter = to_meter
  @factor = factor
  @name = name
end

Instance Attribute Details

#factorObject (readonly)

Returns the value of attribute factor.



3
4
5
# File 'lib/unit.rb', line 3

def factor
  @factor
end

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/unit.rb', line 3

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/unit.rb', line 3

def name
  @name
end

#to_meterObject (readonly)

Returns the value of attribute to_meter.



3
4
5
# File 'lib/unit.rb', line 3

def to_meter
  @to_meter
end

Class Method Details

.get(id) ⇒ Object



27
28
29
# File 'lib/unit.rb', line 27

def self.get(id)
  self.list.find {|ellipsoid| ellipsoid.id == id}
end

.listObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/unit.rb', line 5

def self.list
  # First get linear units
  pointer_to_array = FFI::Pointer.new(Api::PJ_UNITS, Api.proj_list_units)
  result = Array.new
  0.step do |i|
    ellipse_info = Api::PJ_UNITS.new(pointer_to_array[i])
    break if ellipse_info[:id].nil?
    result << self.new(ellipse_info[:id], ellipse_info[:to_meter], ellipse_info[:factor], ellipse_info[:name])
  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|
      ellipse_info = Api::PJ_UNITS.new(pointer_to_array[i])
      break result if ellipse_info[:id].nil?
      result << self.new(ellipse_info[:id], ellipse_info[:to_meter], ellipse_info[:factor], ellipse_info[:name])
    end
  end
  result
end

Instance Method Details

#<=>(other) ⇒ Object



38
39
40
# File 'lib/unit.rb', line 38

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

#==(other) ⇒ Object



42
43
44
# File 'lib/unit.rb', line 42

def ==(other)
  self.id == other.id
end

#inspectObject



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

def inspect
  "#<#{self.class} id=\"#{id}\", to_meter=\"#{to_meter}\", factor=\"#{factor}\", name=\"#{name}\">"
end

#to_sObject



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

def to_s
  self.id
end