Class: MapKit::DataTypes::CoordinateSpan

Inherits:
Object
  • Object
show all
Defined in:
lib/map-kit-wrapper/map_kit_data_types.rb

Overview

Wrapper for MKCoordinateSpan

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ CoordinateSpan

Initializer for CoordinateSpan

  • Args :

The initializer takes a variety of arguments

CoordinateSpan.new(1,2)
CoordinateSpan.new([1,2])
CoordinateSpan.new({:latitude_delta => 1, :longitude_delta => 2})
CoordinateSpan.new(CoordinateSpan)
CoordinateSpan.new(MKCoordinateSpan)


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/map-kit-wrapper/map_kit_data_types.rb', line 33

def initialize(*args)
  args.flatten!
  self.latitude_delta, self.longitude_delta =
      case args.size
        when 1
          arg = args.first
          case arg
            when MKCoordinateSpan
              [arg.latitudeDelta, arg.longitudeDelta]
            when CoordinateSpan
              [arg.latitude_delta, arg.longitude_delta]
            when Hash
              [arg[:latitude_delta], arg[:longitude_delta]]
          end
        when 2
          [args[0], args[1]]
      end
end

Instance Attribute Details

#latitude_deltaObject

Attribute reader



20
21
22
# File 'lib/map-kit-wrapper/map_kit_data_types.rb', line 20

def latitude_delta
  @latitude_delta
end

#longitude_deltaObject

Attribute reader



20
21
22
# File 'lib/map-kit-wrapper/map_kit_data_types.rb', line 20

def longitude_delta
  @longitude_delta
end

Instance Method Details

#apiObject

Returns the wrapped iOS MKCoordinateSpan object

  • Returns :

    • A MKCoordinateSpan representation of self



58
59
60
# File 'lib/map-kit-wrapper/map_kit_data_types.rb', line 58

def api
  MKCoordinateSpanMake(@latitude_delta, @longitude_delta)
end

#to_aObject

Get self as an Array

  • Returns :

    • [latitude_delta, longitude_delta]



88
89
90
# File 'lib/map-kit-wrapper/map_kit_data_types.rb', line 88

def to_a
  [@latitude_delta, @longitude_delta]
end

#to_hObject

Get self as a Hash

  • Returns :

    • {:latitude_delta => latitude_delta, :longitude_delta => longitude_delta}



98
99
100
# File 'lib/map-kit-wrapper/map_kit_data_types.rb', line 98

def to_h
  {:latitude_delta => @latitude_delta, :longitude_delta => @longitude_delta}
end

#to_sObject

Get self as a String

  • Returns :

    • "{:latitude_delta => latitude_delta, :longitude_delta => longitude_delta}"



108
109
110
# File 'lib/map-kit-wrapper/map_kit_data_types.rb', line 108

def to_s
  to_h.to_s
end