Class: Quake::Event
- Inherits:
-
Object
- Object
- Quake::Event
- Defined in:
- lib/quake/event.rb
Instance Attribute Summary collapse
-
#datetime ⇒ Object
Returns the value of attribute datetime.
-
#depth ⇒ Object
Returns the value of attribute depth.
-
#id ⇒ Object
Returns the value of attribute id.
-
#latitude ⇒ Object
Returns the value of attribute latitude.
-
#longitude ⇒ Object
Returns the value of attribute longitude.
-
#magnitude ⇒ Object
Returns the value of attribute magnitude.
-
#nst ⇒ Object
Returns the value of attribute nst.
-
#region ⇒ Object
Returns the value of attribute region.
-
#source ⇒ Object
Returns the value of attribute source.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
- .last_day(criteria = {}) ⇒ Object
- .last_hour(criteria = {}) ⇒ Object
- .last_week(criteria = {:min_magnitude => 2.5}) ⇒ Object
Instance Method Summary collapse
- #distance_from(lat, long) ⇒ Object
-
#initialize(raw) ⇒ Event
constructor
A new instance of Event.
Constructor Details
#initialize(raw) ⇒ Event
Returns a new instance of Event.
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/quake/event.rb', line 40 def initialize(raw) self.source = raw[0] self.id = raw[1] self.version = raw[2].to_i self.datetime = DateTime.strptime(raw[3], fmt="%A, %B %d, %Y %H:%M:%S UTC") self.latitude = raw[4].to_f self.longitude = raw[5].to_f self.magnitude = raw[6].to_f self.depth = raw[7].to_f self.nst = raw[8].to_i self.region = raw[9] end |
Instance Attribute Details
#datetime ⇒ Object
Returns the value of attribute datetime.
10 11 12 |
# File 'lib/quake/event.rb', line 10 def datetime @datetime end |
#depth ⇒ Object
Returns the value of attribute depth.
14 15 16 |
# File 'lib/quake/event.rb', line 14 def depth @depth end |
#id ⇒ Object
Returns the value of attribute id.
8 9 10 |
# File 'lib/quake/event.rb', line 8 def id @id end |
#latitude ⇒ Object
Returns the value of attribute latitude.
11 12 13 |
# File 'lib/quake/event.rb', line 11 def latitude @latitude end |
#longitude ⇒ Object
Returns the value of attribute longitude.
12 13 14 |
# File 'lib/quake/event.rb', line 12 def longitude @longitude end |
#magnitude ⇒ Object
Returns the value of attribute magnitude.
13 14 15 |
# File 'lib/quake/event.rb', line 13 def magnitude @magnitude end |
#nst ⇒ Object
Returns the value of attribute nst.
15 16 17 |
# File 'lib/quake/event.rb', line 15 def nst @nst end |
#region ⇒ Object
Returns the value of attribute region.
16 17 18 |
# File 'lib/quake/event.rb', line 16 def region @region end |
#source ⇒ Object
Returns the value of attribute source.
7 8 9 |
# File 'lib/quake/event.rb', line 7 def source @source end |
#version ⇒ Object
Returns the value of attribute version.
9 10 11 |
# File 'lib/quake/event.rb', line 9 def version @version end |
Class Method Details
.last_day(criteria = {}) ⇒ Object
23 24 25 26 |
# File 'lib/quake/event.rb', line 23 def self.last_day(criteria = {}) raw_items = CSV.parse(Curl::Easy.perform(DAY).body_str) create_events(raw_items, criteria) end |
.last_hour(criteria = {}) ⇒ Object
28 29 30 31 |
# File 'lib/quake/event.rb', line 28 def self.last_hour(criteria = {}) raw_items = CSV.parse(Curl::Easy.perform(HOUR).body_str) create_events(raw_items, criteria) end |
.last_week(criteria = {:min_magnitude => 2.5}) ⇒ Object
18 19 20 21 |
# File 'lib/quake/event.rb', line 18 def self.last_week(criteria = {:min_magnitude => 2.5}) raw_items = CSV.parse(Curl::Easy.perform(WEEK).body_str) create_events(raw_items, criteria) end |
Instance Method Details
#distance_from(lat, long) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/quake/event.rb', line 33 def distance_from(lat, long) (Math.acos(Math.sin(self.latitude) * Math.sin(lat) + Math.cos(self.latitude) * Math.cos(lat) * Math.cos(self.longitude - long)) * SPHERICAL_APPROX_OF_EARTH).round(2) end |