class Bluemoon::Area

Constants

PROXIMITY

Public Class Methods

add() click to toggle source
# 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() click to toggle source
# File lib/bluemoon/area.rb, line 17
def all
  Array(Plist::parse_xml(plist_filename)).map do |area|
    self.new(area)
  end
end
list() click to toggle source
# 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() click to toggle source
# File lib/bluemoon/area.rb, line 29
def plist_filename
  "#{ENV['HOME']}/Library/Preferences/com.bluemoon.locations"
end
remove(i) click to toggle source
# 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

Public Instance Methods

contains?(location) click to toggle source
# File lib/bluemoon/area.rb, line 42
def contains?(location)
  location.distance(coordinates) < PROXIMITY
end
to_s() click to toggle source
# File lib/bluemoon/area.rb, line 46
def to_s
  coordinates.join(', ')
end