Class: MapKit::DataTypes::MapPoint

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

Overview

Wrapper for MKMapPoint

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ MapPoint

Initializer for MapPoint

  • Args :

The initializer takes a variety of arguments

MapPoint.new(50,45)
MapPoint.new([50,45])
MapPoint.new({:x => 50, :y => 45})
MapPoint.new(MKMapPoint)


223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/map-kit-wrapper/map_kit_data_types.rb', line 223

def initialize(*args)
  args.flatten!
  self.x, self.y =
      case args.size
        when 1
          arg = args[0]
          case arg
            when Hash
              [arg[:x], arg[:y]]
            else
              [arg.x, arg.y]
          end
        when 2
          [args[0], args[1]]
      end
end

Instance Attribute Details

#xObject

Attribute reader



211
212
213
# File 'lib/map-kit-wrapper/map_kit_data_types.rb', line 211

def x
  @x
end

#yObject

Attribute reader



211
212
213
# File 'lib/map-kit-wrapper/map_kit_data_types.rb', line 211

def y
  @y
end

Instance Method Details

#apiObject

Returns the wrapped iOS MKMapPoint object

  • Returns :

    • A MKMapPoint representation of self



246
247
248
# File 'lib/map-kit-wrapper/map_kit_data_types.rb', line 246

def api
  MKMapPointMake(@x, @y)
end

#to_aObject

Get self as an Array

  • Returns :

    • [x, y]



276
277
278
# File 'lib/map-kit-wrapper/map_kit_data_types.rb', line 276

def to_a
  [@x, @y]
end

#to_hObject

Get self as a Hash

  • Returns :

    • {:x => x, :y => y}



286
287
288
# File 'lib/map-kit-wrapper/map_kit_data_types.rb', line 286

def to_h
  {:x => @x, :y => @y}
end

#to_sObject

Get self as a String

  • Returns :

    • "{:x => x, :y => y}"



296
297
298
# File 'lib/map-kit-wrapper/map_kit_data_types.rb', line 296

def to_s
  to_h.to_s
end