Class: Libgeo::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/libgeo/formatter.rb,
lib/libgeo/formatter/compiler.rb,
lib/libgeo/formatter/evaluator.rb

Overview

Class: coordinate formatter

Compiles sprintf-like patterns and present given Coordinate as a DMS string

Example:

coord = Latitude.new(:N, 48, 4, 15.7)
my_format = Formatter.new('%H%d°%2M′')
my_format.format(coord) # => 'N48°04.26306′'

Defined Under Namespace

Classes: Compiler, Evaluator

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#patternObject (readonly)

Source pattern



26
27
28
# File 'lib/libgeo/formatter.rb', line 26

def pattern
  @pattern
end

Instance Method Details

#format(coordinate, evaluator = Evaluator) ⇒ Object

Create new string representing coordinate

Params:

  • coordinate Latitude|Longitude source coordinate
  • evaluator Class private

Returns: String formatted string



37
38
39
# File 'lib/libgeo/formatter.rb', line 37

def format(coordinate, evaluator=Evaluator)
  evaluator.new(coordinate).instance_eval(expression)
end

#inspectObject Also known as: to_s, pretty_inspect

Represent instance as string



44
45
46
# File 'lib/libgeo/formatter.rb', line 44

def inspect
  "#<Libgeo::Formatter pattern=(#{pattern})>"
end