quake 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -29,9 +29,11 @@ Fetch all the earthquakes from the past hour:
29
29
 
30
30
  events = Quake::Event.last_hour
31
31
 
32
- Fetch all the earthquakes from the past week with a magnitude of at least 2:
32
+ Fetch all the earthquakes from the past [week|day|hour] with minimum and/or maximum magnitudes:
33
33
 
34
- events = Quake::Event.last_week(2)
34
+ events = Quake::Event.last_week :min_magnitude => 3
35
+ events = Quake::Event.last_week :max_magnitude => 4
36
+ events = Quake::Event.last_week :min_magnitude => 3, :max_magnitude => 4
35
37
 
36
38
  Questions or Problems?
37
39
  ----------------------
@@ -15,19 +15,19 @@ module Quake
15
15
  attr_accessor :nst
16
16
  attr_accessor :region
17
17
 
18
- def self.last_week(minimum_magnitude=2.5)
18
+ def self.last_week(criteria = {:min_magnitude => 2.5, :max_magnitude => 10})
19
19
  raw_items = CSV.parse(Curl::Easy.perform(WEEK).body_str)
20
- create_events(raw_items, minimum_magnitude)
20
+ create_events(raw_items, criteria)
21
21
  end
22
22
 
23
- def self.last_day(minimum_magnitude=0)
23
+ def self.last_day(criteria = {:max_magnitude => 10})
24
24
  raw_items = CSV.parse(Curl::Easy.perform(DAY).body_str)
25
- create_events(raw_items, minimum_magnitude)
25
+ create_events(raw_items, criteria)
26
26
  end
27
27
 
28
- def self.last_hour(minimum_magnitude=0)
28
+ def self.last_hour(criteria = {:max_magnitude => 10})
29
29
  raw_items = CSV.parse(Curl::Easy.perform(HOUR).body_str)
30
- create_events(raw_items, minimum_magnitude)
30
+ create_events(raw_items, criteria)
31
31
  end
32
32
 
33
33
  def initialize(raw)
@@ -45,14 +45,22 @@ module Quake
45
45
 
46
46
  private
47
47
 
48
- def self.create_events(raw_items, minimum_magnitude)
48
+ def self.create_events(raw_items, criteria)
49
+ criteria[:max_magnitude] = 10 unless criteria[:max_magnitude]
49
50
  raw_items.shift
50
51
  events = []
51
52
  raw_items.each do |raw_item|
52
53
  event = Event.new(raw_item)
53
- if event.magnitude >= minimum_magnitude
54
- events << Event.new(raw_item)
54
+ valid_event = true
55
+ criteria.keys.each do |criterion|
56
+ case criterion
57
+ when :min_magnitude
58
+ valid_event = false unless event.magnitude >= criteria[criterion]
59
+ when :max_magnitude
60
+ valid_event = false unless event.magnitude <= criteria[criterion]
61
+ end
55
62
  end
63
+ events << Event.new(raw_item) if valid_event
56
64
  end
57
65
  events
58
66
  end
@@ -1,3 +1,3 @@
1
1
  module Quake
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -18,19 +18,32 @@ class EventTests < MiniTest::Unit::TestCase
18
18
  assert(events.count > 0)
19
19
  end
20
20
 
21
- def test_recent_events_week_with_magnitude_of_two
22
- events = Quake::Event.last_week(4)
23
- events.each { assert(events[0].magnitude >= 4) }
21
+ def test_recent_events_week_with_min_magnitude_of_three
22
+ events = Quake::Event.last_week :min_magnitude => 3
23
+ events.each { assert(events[0].magnitude >= 3) }
24
24
  end
25
25
 
26
- def test_recent_events_day_with_magnitude_of_two
27
- events = Quake::Event.last_day(2)
26
+ def test_recent_events_day_with_min_magnitude_of_two
27
+ events = Quake::Event.last_day :min_magnitude => 2
28
28
  events.each { assert(events[0].magnitude >= 2) }
29
29
  end
30
30
 
31
- def test_recent_events_hour_with_magnitude_of_two
32
- events = Quake::Event.last_hour(1)
31
+ def test_recent_events_hour_with_min_magnitude_of_one
32
+ events = Quake::Event.last_hour :min_magnitude => 1
33
33
  events.each { assert(events[0].magnitude >= 1) }
34
34
  end
35
35
 
36
+ def test_recent_events_week_with_min_magnitude_of_three_max_magnitude_four
37
+ events = Quake::Event.last_week :min_magnitude => 3, :max_magnitude => 4
38
+ events.each do |event|
39
+ assert(event.magnitude >= 3)
40
+ assert(event.magnitude <= 4)
41
+ end
42
+ end
43
+
44
+ def test_recent_events_hour_with_bogus_criteria
45
+ events = Quake::Event.last_hour :foo => 1
46
+ assert(events.count > 0)
47
+ end
48
+
36
49
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quake
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-17 00:00:00.000000000Z
12
+ date: 2011-08-18 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: curb
16
- requirement: &70198107885880 !ruby/object:Gem::Requirement
16
+ requirement: &70213556338760 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 0.7.15
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70198107885880
24
+ version_requirements: *70213556338760
25
25
  description: A library exposing the U.S. Geological Survey's real-time earthquake
26
26
  data
27
27
  email: