Class: Puppeteer::Geolocation

Inherits:
Object
  • Object
show all
Defined in:
lib/puppeteer/geolocation.rb

Instance Method Summary collapse

Constructor Details

#initialize(latitude:, longitude:, accuracy: 0) ⇒ Geolocation

Returns a new instance of Geolocation.

Parameters:

  • latitude (Fixnum)
  • longitude (Fixnum)
  • accuracy (Fixnum) (defaults to: 0)


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/puppeteer/geolocation.rb', line 5

def initialize(latitude:, longitude:, accuracy: 0)
  unless (-180..180).include?(longitude)
    raise ArgumentError.new("Invalid longitude \"#{longitude}\": precondition -180 <= LONGITUDE <= 180 failed.")
  end
  unless (-90..90).include?(latitude)
    raise ArgumentError.new("Invalid latitude \"#{latitude}\": precondition -90 <= LATITUDE <= 90 failed.")
  end
  if accuracy < 0
    raise ArgumentError.new("Invalid accuracy \"#{longitude}\": precondition 0 <= ACCURACY failed.")
  end

  @latitude = latitude
  @longitude = longitude
  @accuracy = accuracy
end

Instance Method Details

#to_hObject



21
22
23
# File 'lib/puppeteer/geolocation.rb', line 21

def to_h
  { latitude: @latitude, longitude: @longitude, accuracy: @accuracy }
end