roker 0.0.0 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/VERSION +1 -1
  2. data/lib/roker.rb +4 -2
  3. data/roker +58 -29
  4. data/roker.gemspec +1 -1
  5. metadata +1 -1
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.1.0
data/lib/roker.rb CHANGED
@@ -142,7 +142,9 @@ protected
142
142
 
143
143
  def weather_xml_soap
144
144
  soap_driver = SOAP::WSDLDriverFactory.new(WSDL_URL).create_rpc_driver
145
- soap_driver.NDFDgen(self.lat, self.lng, WSDL_PRODUCT, self.started_at.strftime("%Y-%m-%dT%H:%M:%S-05:00"), self.ended_at.strftime("%Y-%m-%dT%H:%M:%S-05:00"), WSDL_PARAMETERS)
145
+ request_started_at = (self.started_at-1).strftime("%Y-%m-%dT%H:%M:%S-05:00")
146
+ request_ended_at = self.ended_at.strftime("%Y-%m-%dT%H:%M:%S-05:00")
147
+ soap_driver.NDFDgen(self.lat, self.lng, WSDL_PRODUCT, request_started_at, request_ended_at, WSDL_PARAMETERS)
146
148
  end
147
149
 
148
150
  def weather_xml_uri
@@ -158,7 +160,7 @@ protected
158
160
  sprintf("http://www.weather.gov/forecasts/xml/sample_products/" +
159
161
  "browser_interface/ndfdBrowserClientByDay.php?" +
160
162
  "&format=24+hourly&numDays=%s&lat=%s&lon=%s&startDate=%s",
161
- num_days, self.lat, self.lng, self.started_at.to_s(:weather))
163
+ num_days, self.lat, self.lng, self.started_at.strftime("%Y-%m-%d"))
162
164
  end
163
165
 
164
166
  def self.parse_time(str='')
data/roker CHANGED
@@ -2,41 +2,70 @@
2
2
  require File.dirname(__FILE__) + '/lib/roker'
3
3
  require 'ruby-debug'
4
4
 
5
- started_at = Time.now.beginning_of_day + 1.day
6
- ended_at = started_at.end_of_day
7
- lat = 37.0625
8
- lng = -95.677068
5
+ args = ARGV.join(' ')
9
6
 
10
- ARGV.each do |a|
11
- # puts "Argument: #{a}"
7
+ help = !(args =~ /--help/).nil?
8
+
9
+ if help
10
+ puts "Roker provides weather forecasts from weather.gov."
11
+ puts "\tUsage: roker [options...]\n"
12
+ puts "\tOptions:"
13
+ puts "\t\t--date DATE\t\t\tForecast date (mm/dd/yyyy)"
14
+ puts "\t\t--lat LATITUDE\t\t\tForecast latitude (37.0625)"
15
+ puts "\t\t--lng LONGITUDE\t\t\tForecast longitude (-95.677)"
16
+ puts "\t\t--xml\t\t\t\tDisplay xml result from weather.gov"
17
+ puts "\t\t--help\t\t\t\tDisplay this help message"
18
+ exit
19
+ end
20
+
21
+ if args =~ /--date *(\d+\/\d+\/\d+)/
22
+ $1 =~ /(\d+)\/(\d+)\/(\d+)/
23
+ started_at = Time.mktime($3.to_i, $1.to_i, $2.to_i, 0, 0, 0, 0, 0).beginning_of_day
12
24
  end
25
+
26
+ lat = $1.to_f if args =~ /--lat *([0-9\.\-\+]+)/
27
+ lng = $1.to_f if args =~ /--lng *([0-9\.\-\+]+)/
28
+
29
+ xml = !(args =~ /--xml/).nil?
30
+
31
+ started_at ||= Time.now.beginning_of_day + 1.day
32
+ ended_at ||= started_at.end_of_day
33
+ lat ||= 37.0625
34
+ lng ||= -95.677068
35
+
36
+ puts "Roker says the forecast for #{started_at.strftime("%B %d, %Y")} in #{lat}, #{lng} is:\n"
37
+
13
38
  roker = Roker.new(:started_at => started_at, :ended_at => ended_at, :lat => lat, :lng => lng)
14
39
 
15
- weather_forecasts_attributes = roker.weather_forecasts_attributes
40
+ forecast_str = ''
16
41
 
17
- forecast = "Roker says the forecast for #{started_at.strftime("%B %d, %Y")} is:\n"
18
- weather_forecasts_attributes.each do |wfa|
42
+ roker.weather_forecasts_attributes.each do |wfa|
19
43
  # wfa => {
20
- # :started_at=>Sat Dec 05 00:17:32 -0500 2009,
21
- # :wind_speed=>7.0,
22
- # :minimum_temperature=>21.0,
23
- # :ended_at=>Sat Dec 05 03:17:32 -0500 2009,
24
- # :wind_direction=>180.0,
25
- # :temperature=>24.0,
26
- # :cloud_cover=>0.0,
27
- # :dewpoint_temperature=>12.0,
28
- # :lat=>37.0625,
29
- # :relative_humidity=>60.0,
30
- # :liquid_precipitation=>0.0,
31
- # :lng=>-95.677068,
32
- # :maximum_temperature=>nil,
33
- # :wave_height=>0.0,
34
- # :probability_of_precipitation=>0.0
44
+ # :started_at => Sat Dec 05 00:17:32 -0500 2009,
45
+ # :ended_at => Sat Dec 05 03:17:32 -0500 2009,
46
+ # :lat => 37.0625,
47
+ # :lng => -95.677068,
48
+ # :wind_speed => 7.0,
49
+ # :minimum_temperature => 21.0,
50
+ # :wind_direction => 180.0,
51
+ # :temperature => 24.0,
52
+ # :cloud_cover => 0.0,
53
+ # :dewpoint_temperature => 12.0,
54
+ # :relative_humidity => 60.0,
55
+ # :liquid_precipitation => 0.0,
56
+ # :maximum_temperature => nil,
57
+ # :wave_height => 0.0,
58
+ # :probability_of_precipitation => 0.0
35
59
  # }
36
- temp = wfa[:temperature].nan? ? '?' : wfa[:temperature].to_i.to_s
37
- pop = wfa[:probability_of_precipitation].nan? ? '?' : wfa[:probability_of_precipitation].to_i.to_s
38
- forecast << wfa[:started_at].strftime("%I:%M%p") + "\t" + temp + " deg" + "\t" + pop + "% P.O.P."
39
- forecast << "\n"
60
+ temp = (wfa[:temperature].nil? || wfa[:temperature].nan?) ? '?' : wfa[:temperature].to_i.to_s
61
+ pop = (wfa[:probability_of_precipitation].nil? || wfa[:probability_of_precipitation].nan?) ? '?' : wfa[:probability_of_precipitation].to_i.to_s
62
+ forecast_str << wfa[:started_at].strftime("%I:%M%p") + "\t" + temp + " deg" + "\t" + pop + "% P.O.P."
63
+ forecast_str << "\n"
40
64
  end
41
65
 
42
- puts forecast
66
+ puts forecast_str
67
+
68
+ if xml
69
+ puts "XML:\n"
70
+ puts roker.weather_xml
71
+ end
data/roker.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{roker}
8
- s.version = "0.0.0"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Greg Sterndale"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Greg Sterndale