Sha256: fbc0d35b02a35936761153f748ded7940c29d0bc52284803088cae1d0a823f1d
Contents?: true
Size: 1001 Bytes
Versions: 2
Compression:
Stored size: 1001 Bytes
Contents
# Responses from Stormglass API are wrapped in this class class Stormglass::Response extend Forwardable # convenience delegate calls (like air_temperature) # to the first hour returned def_delegators :first, *Stormglass::Hour::VALUES def initialize(src) @src = JSON.parse(src) end # an array of Stormglass::Hour instances def hours @hours ||= [] return @hours if !@hours.empty? src['hours'].each{|h| @hours << Stormglass::Hour.new(h) } @hours end def src @src end def inspect string = '#<' + "#{self.class.to_s} remaining_requests=#{remaining_requests}, " string +="hours=#{hours.to_s}> " string end def first hours.first end def last hours.last end # takes a string like "7PM EST" and returns the relevant hour if found def find(string) hours.find{|h| h.time == Time.parse(string)} end def meta src['meta'] end def remaining_requests meta['dailyQuota'] - meta['requestCount'] end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
stormglass-0.2.0 | lib/stormglass/response.rb |
stormglass-0.1.1 | lib/stormglass/response.rb |