rubymotion-community / BubbleWrap

Cocoa wrappers and helpers for RubyMotion (Ruby for iOS and OS X) - Making Cocoa APIs more Ruby like, one API at a time. Fork away and send your pull requests
Other
1.18k stars 208 forks source link

Adds BW::Location.get_compass & BW::Location.get_compass_once #348

Closed markrickert closed 10 years ago

markrickert commented 10 years ago

Returns a hash of a CLHeading object in the form of:

{
  magnetic_heading: newHeading.magneticHeading,
  true_heading: newHeading.trueHeading,
  accuracy: newHeading.headingAccuracy,
  timestamp: newHeading.timestamp,
}

Example usage:

BW::Location.get_compass do |heading|
  puts heading[:magnetic_heading] # Fires continuously while the device is rotating
end

or

BW::Location.get_compass_once do |heading|
  puts heading[:magnetic_heading]  # Fires once on the first device rotation
end

Tests:

I added tests for the entire spectrum of this feature:

799 specifications (1186 requirements), 0 failures, 0 errors
colinta commented 10 years ago

Looks great, thanks for keeping these specs thorough, Mark!

The only thing I would request here is an update to the README.

markrickert commented 10 years ago

Ahh. Yeah, i can definitely update the readme.

markrickert commented 10 years ago

Readme update is complete.

screenshot 2014-02-26 11 13 16

colinta commented 10 years ago

Nice! @clayallsopp @supermarin I'll defer to you guys for merging.

supermarin commented 10 years ago

Looks good to me, will leave it for @clayallsopp to press the button

jamonholmgren commented 10 years ago

Not to throw a monkey wrench into this, but what about using an OpenStruct so you can use either the [:symbol] syntax or dot notation?

jamonholmgren commented 10 years ago

I could just wrap the hash in OpenStruct myself inside the block, though, so it's not a big deal.

markrickert commented 10 years ago

While a nice idea, I was trying to mimic the functionality of the other methods in the location module. The other methods return hashes to the block, so I didn't want to deviate form that.

colinta commented 10 years ago

Looks like the other Location methods in particular return a hash, so yeah probably best to imitate that.

jamonholmgren commented 10 years ago

Ah, yeah, gotcha. I can do my OpenStruct magic myself. ;)

clayallsopp commented 10 years ago

:+1: this is great, thanks @markrickert. apologies for the delay!