Class: Silva::System::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/silva/system/base.rb

Overview

Provides basic utility functions.

Direct Known Subclasses

En, Gridref, Osgb36, Wgs84

Constant Summary collapse

DEFAULT_PARAMS =

Default parameters can be specified for each system.

{}
REQUIRED_PARAMS =

Some parameters must be given

[]

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Base

Create the given system with relevant options.

Parameters:

  • options (Hash)

    Parameters relevant to the given system.



17
18
19
20
21
22
# File 'lib/silva/system/base.rb', line 17

def initialize(options)
  @system_name = self.class.name.split('::').last.downcase.to_sym
  options = self.class::DEFAULT_PARAMS.merge(options)
  params_satisfied?(options)
  options.each {|param, val| set_param(param, val) }
end

Instance Method Details

#to(target_system_name, options = nil) ⇒ Silva::System

Transforms the base system to a different system.

Parameters:

  • target_system_name (Symbol)

    The system to convert to.

  • options (Hash) (defaults to: nil)

    Parameters relevant to the target system.

Returns:

  • (Silva::System)

    A new location system of type target_system_name.



30
31
32
33
34
35
36
37
# File 'lib/silva/system/base.rb', line 30

def to(target_system_name, options = nil)
  return self if target_system_name == @system_name
  to_method = "to_#{target_system_name}".to_sym
  unless respond_to?(to_method, true)
    raise Silva::InvalidTransformError, "#{@system_name} cannot be transformed to #{target_system_name}."
  end
  send(to_method, options)
end