Class: Stormglass::Response
- Inherits:
-
Object
- Object
- Stormglass::Response
- Extended by:
- Forwardable
- Defined in:
- lib/stormglass/response.rb
Overview
Responses from Stormglass API are wrapped in this class
Instance Method Summary collapse
-
#find(string) ⇒ Object
takes a string like “7PM EST” and returns the relevant hour if found.
- #first ⇒ Object
-
#hours ⇒ Object
an array of Stormglass::Hour instances.
-
#initialize(src) ⇒ Response
constructor
A new instance of Response.
- #inspect ⇒ Object
- #last ⇒ Object
- #meta ⇒ Object
- #remaining_requests ⇒ Object
- #src ⇒ Object
Constructor Details
#initialize(src) ⇒ Response
Returns a new instance of Response.
10 11 12 |
# File 'lib/stormglass/response.rb', line 10 def initialize(src) @src = JSON.parse(src) end |
Instance Method Details
#find(string) ⇒ Object
takes a string like “7PM EST” and returns the relevant hour if found
41 42 43 |
# File 'lib/stormglass/response.rb', line 41 def find(string) hours.find{|h| h.time == Time.parse(string)} end |
#first ⇒ Object
32 33 34 |
# File 'lib/stormglass/response.rb', line 32 def first hours.first end |
#hours ⇒ Object
an array of Stormglass::Hour instances
15 16 17 18 19 20 |
# File 'lib/stormglass/response.rb', line 15 def hours @hours ||= [] return @hours if !@hours.empty? src['hours'].each{|h| @hours << Stormglass::Hour.new(h) } @hours end |
#inspect ⇒ Object
26 27 28 29 30 |
# File 'lib/stormglass/response.rb', line 26 def inspect string = '#<' + "#{self.class.to_s} remaining_requests=#{remaining_requests}, " string +="hours=#{hours.to_s}> " string end |
#last ⇒ Object
36 37 38 |
# File 'lib/stormglass/response.rb', line 36 def last hours.last end |
#meta ⇒ Object
45 46 47 |
# File 'lib/stormglass/response.rb', line 45 def src['meta'] end |
#remaining_requests ⇒ Object
49 50 51 |
# File 'lib/stormglass/response.rb', line 49 def remaining_requests ['dailyQuota'] - ['requestCount'] end |
#src ⇒ Object
22 23 24 |
# File 'lib/stormglass/response.rb', line 22 def src @src end |