Class: Proj::Operation

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

Overview

Represents a PROJ operation (projection or conversion method). Each operation has an identifier and a human-readable description.

Examples:

List all operations

operations = Proj::Operation.list
operations.each { |op| puts "#{op.id}: #{op.description}" }

Find a specific operation

op = Proj::Operation.get("aea")
puts op.description  #=> "Albers Equal Area"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, description) ⇒ Operation

Creates a new Operation.

Parameters:

  • id (String)

    The operation identifier

  • description (String)

    Human-readable description



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

def initialize(id, description)
  @id = id
  @description = description
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



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

attr_reader :id, :description

#idString (readonly)

Returns The operation identifier (e.g., “aea”, “merc”).

Returns:

  • (String)

    The operation identifier (e.g., “aea”, “merc”)



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

def id
  @id
end

Class Method Details

.get(id) ⇒ Operation?

Finds an operation by its identifier.

Parameters:

  • id (String)

    The operation identifier to search for

Returns:

  • (Operation, nil)

    The matching operation or nil if not found



40
41
42
# File 'lib/proj/operation.rb', line 40

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

.listArray<Operation>

Returns a list of all available operations.

Returns:



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/proj/operation.rb', line 22

def self.list
  pointer_to_array = FFI::Pointer.new(Api::PjList, Api.proj_list_operations)
  result = Array.new
  0.step do |i|
    operation_info = Api::PjList.new(pointer_to_array[i])
    break result if operation_info[:id].nil?
    id = operation_info[:id]
    description = operation_info[:descr].read_pointer.read_string.force_encoding('UTF-8')
    result << self.new(id, description)
  end
  result
end

Instance Method Details

#==(other) ⇒ Object



55
56
57
# File 'lib/proj/operation.rb', line 55

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

#inspectObject



63
64
65
# File 'lib/proj/operation.rb', line 63

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

#to_sObject



59
60
61
# File 'lib/proj/operation.rb', line 59

def to_s
  self.id
end