rb_wunderground 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,7 +4,8 @@ require 'hashie'
4
4
 
5
5
  module RbWunderground
6
6
  class Base
7
- FEATURES = %w[conditions forecast forecast10day almanac hourly hourly10day alerts astronomy tide yesterday currenthurricaine geolookup rawtide webcams]
7
+ FEATURES = %w[alerts almanac astronomy conditions currenthurricaine forecast forecast10day
8
+ geolookup hourly hourly10day rawtide tide webcams yesterday]
8
9
 
9
10
  attr_reader :api_key
10
11
  attr_reader :format
@@ -20,17 +21,25 @@ module RbWunderground
20
21
 
21
22
  FEATURES.each do |name|
22
23
  define_method(name) do |arg|
23
- url = ""
24
- url << base_url << name << "/q/" << arg << format
24
+ url = build_url([name], arg)
25
25
  fetch_result(url)
26
26
  end
27
27
  end
28
28
 
29
- def method_missing(name, *args, &block)
29
+ def method_missing(meth, *args, &block)
30
+ name = meth.to_s
30
31
  if name =~ /^history_(.+)$/ || name =~ /^planner_(.+)$/
31
- url = ""
32
- url << base_url << name.to_s << "/q/" << args[0] << format
32
+ url = build_url([name], args[0])
33
33
  fetch_result(url)
34
+ elsif name.scan("_and_").any?
35
+ list = name.split("_and_").reject { |n| n=~ /^history_(.+)$/ || n =~ /^planner_(.+)$/ }
36
+ if list & FEATURES == list
37
+ features = name.split("_and_")
38
+ url = build_url(features, args[0])
39
+ fetch_result(url)
40
+ else
41
+ super
42
+ end
34
43
  else
35
44
  super
36
45
  end
@@ -42,6 +51,15 @@ module RbWunderground
42
51
  end
43
52
  private :fetch_result
44
53
 
54
+ def build_url(features, arg)
55
+ url = ""
56
+ url << base_url
57
+ features.each { |f| url << f << '/' }
58
+ url << 'q/' << arg << format
59
+ url
60
+ end
61
+ private :build_url
62
+
45
63
  end
46
64
 
47
65
  end
@@ -1,3 +1,3 @@
1
1
  module RbWunderground
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rb_wunderground
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: