Class: MapKit::DataTypes::MapRect

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

Overview

Wrapper for MKMapRect

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ MapRect

Initializer for MapRect

  • Args :

The initializer takes a variety of arguments

MapRect.new(x, y, width, height)
MapRect.new([x, y], [width, height])
MapRect.new({:origin => {:x => 5.0, :y => 8.0}, :size => {:width => 6.0, :height => 9.0}})
MapRect.new(MapPoint, MapSize)
MapRect.new(MKMapPoint, MKMapSize)
MapRect.new(MapRect)
MapRect.new(MKMapRect)


423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
# File 'lib/map-kit-wrapper/map_kit_data_types.rb', line 423

def initialize(*args)
  self.origin, self.size =
      case args.size
        when 1
          arg = args[0]
          case arg
            when Hash
              [arg[:origin], arg[:size]]
            else
              [arg.origin, arg.size]
          end
        when 2
          [args[0], args[1]]
        when 4
          [[args[0], args[1]], [args[2], args[3]]]
      end
end

Instance Attribute Details

#originObject

Attribute reader



407
408
409
# File 'lib/map-kit-wrapper/map_kit_data_types.rb', line 407

def origin
  @origin
end

#sizeObject

Attribute reader



407
408
409
# File 'lib/map-kit-wrapper/map_kit_data_types.rb', line 407

def size
  @size
end

Instance Method Details

#apiObject

Returns the wrapped iOS MKMapRect object

  • Returns :

    • A MKMapRect representation of self



447
448
449
# File 'lib/map-kit-wrapper/map_kit_data_types.rb', line 447

def api
  MKMapRectMake(@origin.x, @origin.y, @size.width, @size.height)
end

#to_hObject

Get self as a Hash

  • Returns :

    • {:origin => {:x => x, :y => y}, :size => {:width => width, :height => height}}



477
478
479
# File 'lib/map-kit-wrapper/map_kit_data_types.rb', line 477

def to_h
  {:origin => @origin.to_h, :size => @size.to_h}
end

#to_sObject

Get self as a String

  • Returns :

    • "{:origin => {:x => x, :y => y}, :size => {:width => width, :height => height}}"



487
488
489
# File 'lib/map-kit-wrapper/map_kit_data_types.rb', line 487

def to_s
  to_h.to_s
end