will_it_rain 0.1.0

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.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NzhkYjU4ODhhYWFkZGE2MjE2NmU5YjhlZTZlYjhhYzU4YjBkNmNhMQ==
5
+ data.tar.gz: !binary |-
6
+ NWU2MjRjNzQ1ZTgxNDkxOWY5YTRkMzgzMWFjODJiZmUzZDY4MDlhOQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ Y2UxZjFlMjYxNmZjZDg5YWQ0MWQwOTRiMjZlN2ExY2Y0YmJjNWE5NDZhMWU4
10
+ NTExNjI1MTU3MGZiMzEyNTFjZmY4NmMxNTBlZTUzNGU2YWJkYTRjMmU5Njk1
11
+ YzA5YjZjYTRjYzM0M2VmYmNiMjM3NGE5ZWRiNGM2Y2I5MGYwZGI=
12
+ data.tar.gz: !binary |-
13
+ NDAxMTFiZDBkMzg2MDc1YjRlZjFjMzM1NTJmMTdmNzExZmRkNGI4ZTA1YjYx
14
+ NjZjODBlYmE0NWIzMDU2NjZiN2E1MmEwN2IyMmY0NjUyNmZiZmVkMDRjYzRl
15
+ ZTlkMTQ4Nzc2YTE0YmViYmZjYTJlZmI2YjU0NjM3ZDgzZWJiNzc=
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.swp
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --order random
@@ -0,0 +1 @@
1
+ will_it_rain
@@ -0,0 +1 @@
1
+ 1.9.3
@@ -0,0 +1,16 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.2.0
6
+ env: RAKE_ENV=test RAILS_ENV=test
7
+ before_install:
8
+ - 'gem install bundler'
9
+ script:
10
+ - 'bundle exec rspec'
11
+ notifications:
12
+ email:
13
+ recipients:
14
+ - humzashah+travis@gmail.com
15
+ on_success: never
16
+ on_failure: always
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in will_it_rain.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Syed Humza Shah
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,46 @@
1
+ # Will It Rain?
2
+
3
+ "Will It Rain?" uses [forecast_io](https://github.com/darkskyapp/forecast-ruby) to determine whether or not it will rain (precipitate, more specifically) at a particular location today. This gem was created primarily to isolate logic from a larger project. I hope it helps you in your weather-related Ruby application.
4
+
5
+ ## How does it work?
6
+
7
+ Different data points are collected from the current day. For each data point, the [probability of precipitation](http://en.wikipedia.org/wiki/Probability_of_precipitation) is considered. If any data point exceeds the threshold, it is considered a "rain day."
8
+
9
+ ## Setup
10
+
11
+ Add the following to your Gemfile and install:
12
+
13
+ ```ruby
14
+ gem 'will_it_rain'
15
+ ```
16
+
17
+ You will first need to signup on [forecast.io](http://forecast.io) and get an API key. You can set the key as a `FORECAST_IO_API_KEY` environment variable; alternatively you can set the API key in the following way:
18
+
19
+ ```ruby
20
+ require 'forecast_io'
21
+ ForecastIO.api_key = your_api_key
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ Find out if there is a chance of rain today:
27
+ ```ruby
28
+ WillItRain.at_location?(latitude, longitude) # returns boolean
29
+ ```
30
+
31
+ The above checks for rain-chances greater than 10% by default. Here is how you can check if chance of rain today is greater than 25%:
32
+ ```ruby
33
+ WillItRain.at_location?(latitude, longitude, 25)
34
+ ```
35
+
36
+ Get likelihood of precipitation along with percentage:
37
+ ```ruby
38
+ WillItRain.with_chances(latitude, longitude) # returns {it_will_rain: boolean, chances: percentage_string}
39
+ WillItRain.with_chances(latitude, longitude, 5) # compare with a value other than 10%
40
+ ```
41
+
42
+ Get readable summaries of daily data points where precipitation probability exceeds 10%:
43
+ ```ruby
44
+ WillItRain.get_summaries(latitude, longitude) # returns array of readable summaries
45
+ WillItRain.get_summaries(latitude, longitude, 25) # adjust default threshold
46
+ ```
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "will_it_rain"
5
+
6
+ require "irb"
7
+ IRB.start
@@ -0,0 +1,5 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
@@ -0,0 +1,7 @@
1
+ %w{
2
+ faraday
3
+ forecast_io
4
+ }.each do |name|
5
+ file_path = "./initializers/#{name}"
6
+ require_relative file_path
7
+ end
@@ -0,0 +1,2 @@
1
+ require 'typhoeus/adapters/faraday'
2
+ Faraday.default_adapter = :typhoeus
@@ -0,0 +1,2 @@
1
+ require "forecast_io"
2
+ ForecastIO.api_key ||= ENV["FORECAST_IO_API_KEY"]
@@ -0,0 +1,39 @@
1
+ require "will_it_rain/version"
2
+ require_relative "../config/initialize"
3
+ require_relative "./will_it_rain/data_point"
4
+
5
+ module WillItRain
6
+ module Default
7
+ THRESHOLD = 10
8
+ SUMMARY = "No chance of precipitation today."
9
+ end
10
+
11
+ module_function
12
+
13
+ def at_location?(latitude, longtitude, threshold=Default::THRESHOLD)
14
+ with_chances(latitude, longtitude, threshold)[:it_will_rain]
15
+ end
16
+
17
+ def with_chances(latitude, longtitude, threshold=Default::THRESHOLD)
18
+ dp = daily_data_points(latitude, longtitude).max_by(&:percentage)
19
+ {it_will_rain: dp.surpasses_threshold?(threshold), chances: "#{dp.percentage}%"}
20
+ end
21
+
22
+ def get_summaries(latitude, longtitude, threshold=Default::THRESHOLD)
23
+ data_points = daily_data_points(latitude, longtitude)
24
+
25
+ if data_points.any? { |dp| dp.surpasses_threshold?(threshold) }
26
+ data_points.map(&:summary).uniq
27
+ else
28
+ [Default::SUMMARY]
29
+ end
30
+ end
31
+
32
+ private
33
+ module_function
34
+
35
+ def daily_data_points(latitude, longtitude)
36
+ forecast = ForecastIO.forecast(latitude, longtitude)
37
+ forecast.daily.data.map { |dp| DataPoint.new(dp) }
38
+ end
39
+ end
@@ -0,0 +1,15 @@
1
+ module WillItRain
2
+ class DataPoint
3
+ # percentage refers to likelihood of precipitation
4
+ attr_accessor :percentage, :summary
5
+
6
+ def initialize(data_point)
7
+ self.percentage = (100 * data_point.precipProbability).round(2)
8
+ self.summary = data_point.summary
9
+ end
10
+
11
+ def surpasses_threshold?(threshold)
12
+ percentage >= threshold
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module WillItRain
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'will_it_rain/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "will_it_rain"
8
+ spec.version = WillItRain::VERSION
9
+ spec.authors = ["Syed Humza Shah"]
10
+ spec.email = ["humzashah+github@gmail.com"]
11
+
12
+ spec.summary = "Use Ruby to determine if it will rain today."
13
+ spec.homepage = "https://github.com/humzashah/will_it_rain"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.required_ruby_version = '>= 1.9.3'
22
+
23
+ spec.add_development_dependency "bundler", ">= 1.7.6"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec"
26
+
27
+ spec.add_dependency "typhoeus"
28
+ spec.add_dependency "forecast_io"
29
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: will_it_rain
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Syed Humza Shah
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-05-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.7.6
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.7.6
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: typhoeus
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: forecast_io
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - humzashah+github@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .rspec
92
+ - .ruby-gemset
93
+ - .ruby-version
94
+ - .travis.yml
95
+ - Gemfile
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - bin/console
100
+ - bin/setup
101
+ - config/initialize.rb
102
+ - config/initializers/faraday.rb
103
+ - config/initializers/forecast_io.rb
104
+ - lib/will_it_rain.rb
105
+ - lib/will_it_rain/data_point.rb
106
+ - lib/will_it_rain/version.rb
107
+ - will_it_rain.gemspec
108
+ homepage: https://github.com/humzashah/will_it_rain
109
+ licenses:
110
+ - MIT
111
+ metadata: {}
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: 1.9.3
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.4.3
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: Use Ruby to determine if it will rain today.
132
+ test_files: []