Class: Bluemoon::Area
- Inherits:
-
Struct
- Object
- Struct
- Bluemoon::Area
- Defined in:
- lib/bluemoon/area.rb
Constant Summary collapse
- PROXIMITY =
400
Instance Attribute Summary collapse
-
#coordinates ⇒ Object
Returns the value of attribute coordinates.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#coordinates ⇒ Object
Returns the value of attribute coordinates
2 3 4 |
# File 'lib/bluemoon/area.rb', line 2 def coordinates @coordinates end |
Class Method Details
.add ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/bluemoon/area.rb', line 6 def add puts "Querying location. This may take a few moments..." File.open(plist_filename, 'w+') do |file| file.write [*all, Location.current].map(&:coordinates).uniq.to_plist end puts "Added #{Location.current} to list of places to enable bluetooth at." puts Location.current.url end |
.all ⇒ Object
17 18 19 20 21 |
# File 'lib/bluemoon/area.rb', line 17 def all Array(Plist::parse_xml(plist_filename)).map do |area| self.new(area) end end |
.list ⇒ Object
23 24 25 26 27 |
# File 'lib/bluemoon/area.rb', line 23 def list all.each_with_index do |location, i| puts "#{(i + 1).to_s.ljust(all.count.to_s.length)}. #{location}" end end |
.plist_filename ⇒ Object
29 30 31 |
# File 'lib/bluemoon/area.rb', line 29 def plist_filename "#{ENV['HOME']}/Library/Preferences/com.bluemoon.locations" end |
.remove(i) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/bluemoon/area.rb', line 33 def remove(i) File.open(plist_filename, 'w+') do |file| file.write all.tap { |a| a.delete(i.to_i - 1) } end list end |
Instance Method Details
#contains?(location) ⇒ Boolean
42 43 44 |
# File 'lib/bluemoon/area.rb', line 42 def contains?(location) location.distance(coordinates) < PROXIMITY end |
#to_s ⇒ Object
46 47 48 |
# File 'lib/bluemoon/area.rb', line 46 def to_s coordinates.join(', ') end |