class Machiawase::Rendezvous
Attributes
address[R]
@!attribute [r] place
@return [Place] the place to rendezvous.
@!attribute [r] places
@return [Array<Place>] the array of given places. @see Place
lat[R]
@!attribute [r] place
@return [Place] the place to rendezvous.
@!attribute [r] places
@return [Array<Place>] the array of given places. @see Place
lon[R]
@!attribute [r] place
@return [Place] the place to rendezvous.
@!attribute [r] places
@return [Array<Place>] the array of given places. @see Place
near_station[R]
@!attribute [r] place
@return [Place] the place to rendezvous.
@!attribute [r] places
@return [Array<Place>] the array of given places. @see Place
place[R]
@!attribute [r] place
@return [Place] the place to rendezvous.
@!attribute [r] places
@return [Array<Place>] the array of given places. @see Place
places[R]
@!attribute [r] place
@return [Place] the place to rendezvous.
@!attribute [r] places
@return [Array<Place>] the array of given places. @see Place
Public Class Methods
new(*places)
click to toggle source
@param places [Array<Place>] the array of places.
# File lib/machiawase/rendezvous.rb, line 16 def initialize(*places) @place = nil @places = places end
Public Instance Methods
to_h()
click to toggle source
@return [Hash] the attributes with Hash format.
# File lib/machiawase/rendezvous.rb, line 46 def to_h h = Hash.new @places.each_with_index do |place, i| h.store("place#{i}", place.to_h) end @place ||= middle_of(*@places) h.store("machiawase", @place.to_h) end
to_json()
click to toggle source
@return [JSON] the attributes with JSON format.
# File lib/machiawase/rendezvous.rb, line 57 def to_json JSON.pretty_generate(to_h) end
to_msgpack()
click to toggle source
# File lib/machiawase/rendezvous.rb, line 61 def to_msgpack to_h.to_msgpack end
Private Instance Methods
centroid(*places)
click to toggle source
# File lib/machiawase/rendezvous.rb, line 72 def centroid(*places) x_sum = 0 y_sum = 0 places.each do |p| x_sum += p.lat y_sum += p.lon end [x_sum/places.length.to_f, y_sum/places.length.to_f] end
middle_of(*places)
click to toggle source
# File lib/machiawase/rendezvous.rb, line 67 def middle_of(*places) c = centroid(*places) @place = Place.new(c[0], c[1]) end