usno-eclipse-solar 0.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e8f8f58724ac2084977f74bf37d9faa9a1c0e29d
4
+ data.tar.gz: ca52a44087bdded29f36996374cd9004a88cc855
5
+ SHA512:
6
+ metadata.gz: d1067c652e0804fb855ec1258f7834f0b4c3a4ac1d23029860c3614735416a5b5cf85195bdb162d7b7822130b7d76ba74c655833b4e484da291300412d43b9dd
7
+ data.tar.gz: 11e20ac4fca041aa404f6c2b5ed4ba5822e3206f9534037ddf86e18a6c43859a182e739ead572f38022c8fec22d24194dfeb9634ecbcb3c81f72a9b19c700fc9
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in usno-eclipse-solar.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Ryan T. Hosford
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,111 @@
1
+ # USNO::Eclipse::Solar
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'usno-eclipse-solar'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install usno-eclipse-solar
18
+
19
+ ## Usage
20
+
21
+ First, `require usno/eclipse/solar`
22
+
23
+ By default, it'll check for the visibility data of the solar eclipse occurring on August 21, 2017.
24
+ A location is always required.
25
+
26
+ ![August 21, 2017](http://aa.usno.navy.mil/data/docs/ats_0412017.gif)
27
+
28
+ ```ruby
29
+ USNO::Eclipse::Solar::Data.new(lat: 30, long: -87).call.data
30
+ ```
31
+
32
+ ```html
33
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
34
+ <html>
35
+ <head>
36
+ <title>Solar Eclipse Computer</title>
37
+ <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
38
+ </head>
39
+ <body>
40
+
41
+ <pre>
42
+ Solar Eclipse of 2017 Aug. 21
43
+ Sun in Partial Eclipse at this Location
44
+ Delta T: 69.4s
45
+
46
+ None given
47
+ Location: W 87°00'00.0", N30°00'00.0", 0m
48
+ (Longitude referred to Greenwich meridian)
49
+
50
+ Sun's Position Vertex
51
+ UT1 Altitude Azimuth Angle Angle
52
+ d h m s ° ° ° °
53
+ Eclipse Begins 21 17:04:27.5 68.9 146.7 304.2 333.4
54
+ Maximum Eclipse 21 18:36:42.3 69.0 212.7
55
+ Eclipse Ends 21 20:03:14.2 54.4 246.5 105.7 51.6
56
+
57
+ Duration: 2h 58m 46.7s
58
+ Magnitude: 0.840
59
+ Obscuration: 80.5%
60
+ </pre>
61
+
62
+ <p><a href="javascript:history.go(-1)">Back to form</a></p>
63
+ </body>
64
+ </html>
65
+ ```
66
+
67
+ ```ruby
68
+ USNO::Eclipse::Solar::Data.new(request_class: USNO::Eclipse::Solar::USRequest, city: "Gulf Shores", state: "Alabama", date: Time.new(2017,8,21)).call.data
69
+ ```
70
+ ```html
71
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
72
+ <html>
73
+ <head>
74
+ <title>Solar Eclipse Computer</title>
75
+ <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
76
+ </head>
77
+ <body>
78
+
79
+ <pre>
80
+ Solar Eclipse of 2017 Aug. 21
81
+ Sun in Partial Eclipse at this Location
82
+ Delta T: 69.4s
83
+
84
+ GULF SHORES, ALABAMA
85
+ Location: W 87°41'24.0", N30°15'36.0", 0m
86
+ (Longitude referred to Greenwich meridian)
87
+
88
+ Sun's Position Vertex
89
+ UT1 Altitude Azimuth Angle Angle
90
+ d h m s ° ° ° °
91
+ Eclipse Begins 21 17:02:33.5 68.1 144.4 304.1 335.2
92
+ Maximum Eclipse 21 18:34:44.6 69.3 209.5
93
+ Eclipse Ends 21 20:01:35.1 55.1 245.0 105.6 52.5
94
+
95
+ Duration: 2h 59m 01.7s
96
+ Magnitude: 0.838
97
+ Obscuration: 80.2%
98
+ </pre>
99
+
100
+ <p><a href="javascript:history.go(-1)">Back to form</a></p>
101
+ </body>
102
+ </html>
103
+ ```
104
+
105
+ ## Contributing
106
+
107
+ 1. Fork it
108
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
109
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
110
+ 4. Push to the branch (`git push origin my-new-feature`)
111
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.pattern = 'test/**/*_test.rb'
6
+ t.libs.push 'test'
7
+ end
8
+
9
+ task :default => :test
@@ -0,0 +1,17 @@
1
+ require "pay_dirt"
2
+
3
+ require_relative "solar/version"
4
+
5
+ require_relative "solar/request"
6
+ require_relative "solar/data"
7
+ require_relative "solar/states"
8
+ require_relative "solar/eclipses"
9
+ require_relative "solar/us_request"
10
+ require_relative "solar/worldwide_request"
11
+
12
+ module USNO
13
+ module Eclipse
14
+ module Solar
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,41 @@
1
+ module USNO
2
+ module Eclipse
3
+ module Solar
4
+ class Data < PayDirt::Base
5
+ def initialize(options = {})
6
+ options = form_options(options)
7
+
8
+ load_options(:date, options) and validate_state
9
+ end
10
+
11
+ def call
12
+ result true, @request_class.new(@request_options).call.data
13
+ end
14
+
15
+ private
16
+ def form_options(options)
17
+ options = {
18
+ request_class: USNO::Eclipse::Solar::WorldWideRequest,
19
+ z_meters: 0,
20
+
21
+ # Default to date when much of the world will experience an eclipse
22
+ date: Time.new(2017, 8, 21)
23
+ }.merge(options)
24
+
25
+ options.merge!({
26
+ request_options: options.reject do |k,_|
27
+ k.to_s == "request_class"
28
+ end
29
+ })
30
+ end
31
+
32
+ def validate_state
33
+ # @z_meters.between?(-90, 10999) # Documented by USNO, but won't fail
34
+ (@city && @state) || (@lat && @long) or raise %q{
35
+ Location required.
36
+ }
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,65 @@
1
+ module USNO
2
+ module Eclipse
3
+ module Solar
4
+ module Eclipses
5
+ def self.by_key_or_value(kv)
6
+ hash.has_value? kv and return kv
7
+
8
+ hash.fetch(formatted_date(kv)) {
9
+ raise "No known solar eclipse at the provided time #{kv} - hint, try USNO::Eclipse::Solar::Eclipses.all"
10
+ }.to_s
11
+ end
12
+
13
+ def self.fetch(kv)
14
+ by_key_or_value(kv)
15
+ end
16
+
17
+ def self.hash
18
+ {
19
+ "200827" => 12008, "20111125" => 42011, "2015320" => 12015,
20
+ "200881" => 22008, "2012520" => 12012, "2015913" => 22015,
21
+ "2009126" => 12009, "2012521" => 12012, "201638" => 12016,
22
+ "2009721" => 22009, "20121113" => 22012, "201639" => 12016,
23
+ "2009722" => 22009, "20121114" => 22012, "201691" => 22016,
24
+ "2010115" => 12010, "201359" => 12013, "2017226" => 12017,
25
+ "2010711" => 22010, "2013510" => 12013, "2017821" => 22017,
26
+ "201114" => 12011, "2013113" => 22013, "20141023" => 22014,
27
+ "201161" => 22011, "2014429" => 12014, "201171" => 32011
28
+ }
29
+ end
30
+
31
+ def self.formatted_date(date)
32
+ date.strftime("%Y%-m%-d")
33
+ end
34
+
35
+ # As reminders
36
+ def self.all
37
+ %w{
38
+ 2008 February 7 (Annular)
39
+ 2008 August 1 (Total)
40
+ 2009 January 26 (Annular)
41
+ 2009 July 21-22 (Total)
42
+ 2010 January 15 (Annular)
43
+ 2010 July 11 (Total)
44
+ 2011 January 4 (Partial)
45
+ 2011 June 1 (Partial)
46
+ 2011 July 1 (Partial)
47
+ 2011 November 25 (Partial)
48
+ 2012 May 20-21 (Annular)
49
+ 2012 November 13-14 (Total)
50
+ 2013 May 9-10 (Annular)
51
+ 2013 November 3 (Total)
52
+ 2014 April 29 (Annular)
53
+ 2014 October 23 (Partial)
54
+ 2015 March 20 (Total)
55
+ 2015 September 13 (Partial)
56
+ 2016 March 8-9 (Total)
57
+ 2016 September 1 (Annular)
58
+ 2017 February 26 (Annular)
59
+ 2017 August 21 (Total)
60
+ }
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,34 @@
1
+ require "uri"
2
+ require "net/http"
3
+
4
+ module USNO
5
+ module Eclipse
6
+ module Solar
7
+ module Request
8
+ private
9
+ def request_response(url = "http://aa.usno.navy.mil/cgi-bin/aa_solecl.pl")
10
+ uri = URI.parse(url)
11
+
12
+ response = Net::HTTP.start(uri.host) do |http|
13
+ request = Net::HTTP::Post.new(uri.path)
14
+
15
+ http_headers.map { |k, v| request[k] = v }
16
+ request.body = request_body
17
+
18
+ http.request request
19
+ end
20
+ end
21
+
22
+ def http_headers
23
+ {
24
+ "Accept" => "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
25
+ "Accept-Language" => "en-US,en;q=0.5",
26
+ "Accept-Encoding" => "gzip,deflate,sdch",
27
+ "Referer" => "http://aa.usno.navy.mil/data/docs/SolarEclipses.php"
28
+ }
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+
@@ -0,0 +1,36 @@
1
+ module USNO
2
+ module Eclipse
3
+ module Solar
4
+ module States
5
+ def self.states
6
+ {
7
+ "Alabama" => "AL", "Alaska" => "AK", "American Samoa" => "AS",
8
+ "Arizona" => "AZ", "Arkansas" => "AR", "California" => "CA",
9
+ "Colorado" => "CO", "Connecticut" => "CT", "Delaware" => "DE",
10
+ "District of Columbia" => "DC", "Florida" => "FL", "Georgia" => "GA",
11
+ "Guam" => "GU", "Hawaii" => "HI", "Idaho" => "ID",
12
+ "Indiana" => "IN", "Iowa" => "IA", "Kansas" => "KS",
13
+ "Kentucky" => "KY", "Louisiana" => "LA", "Maine" => "ME",
14
+ "Maryland" => "MD", "Massachusetts" => "MA", "Michigan" => "MI",
15
+ "Minnesota" => "MN", "Mississippi" => "MS", "Missouri" => "MO",
16
+ "Montana" => "MT", "Nebraska" => "NE", "Nevada" => "NV",
17
+ "New Hampshire" => "NH", "New Jersey" => "NJ", "New Mexico" => "NM",
18
+ "New York" => "NY", "North Carolina" => "NC", "North Dakota" => "ND",
19
+ "N. Mariana Islands" => "MP", "Ohio" => "OH", "Oklahoma" => "OK",
20
+ "Oregon" => "OR", "Pennsylvania" => "PA", "Puerto Rico" => "PR",
21
+ "Rhode Island" => "RI", "South Carolina" => "SC", "South Dakota" => "SD",
22
+ "Tennessee" => "TN", "Texas" => "TX", "Utah" => "UT",
23
+ "Vermont" => "VT", "Virgin Islands" => "VI", "Virginia" => "VA",
24
+ "Washington" => "WA", "West Virginia" => "WV", "Wisconsin" => "WI",
25
+ "Wyoming" => "WY", "Illinois" => "IL"
26
+ }
27
+ end
28
+
29
+ def self.by_key_or_value(kv)
30
+ states.has_value? kv and return kv
31
+ states.fetch(kv) { raise "USNO State not recognized" }
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,37 @@
1
+ require "uri"
2
+ require "net/http"
3
+
4
+ module USNO
5
+ module Eclipse::Solar
6
+ class USRequest < PayDirt::Base
7
+ include USNO::Eclipse::Solar::Request
8
+
9
+ def initialize(options = {})
10
+ options = {
11
+ }.merge(options)
12
+
13
+ load_options(:city, :state, :date, options)
14
+ end
15
+
16
+ def call
17
+ return result(true, request_response.body)
18
+ end
19
+
20
+ private
21
+ def place
22
+ "st=#{USNO::Eclipse::Solar::States.by_key_or_value(@state)}&place=#{@city}&hh1=#{@z_meters}"
23
+ end
24
+
25
+
26
+
27
+ def request_body
28
+ %W{
29
+ FFX=1
30
+ xxecl=#{USNO::Eclipse::Solar::Eclipses.fetch(@date)}
31
+ #{place}
32
+ ZZZ=END
33
+ }.join("&")
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,7 @@
1
+ module USNO
2
+ module Eclipse
3
+ module Solar
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,66 @@
1
+ require "uri"
2
+ require "net/http"
3
+
4
+ module USNO
5
+ module Eclipse
6
+ module Solar
7
+ class WorldWideRequest < PayDirt::Base
8
+ include USNO::Eclipse::Solar::Request
9
+
10
+ def initialize(options = {})
11
+ options = {
12
+ z_meters: 0,
13
+ days: 5,
14
+ lat_minutes: 0, lat_seconds: 0, long_minutes: 0, long_seconds: 0
15
+ }.merge(options)
16
+
17
+
18
+ load_options(:long, :lat, :date, options)
19
+ end
20
+
21
+ def call
22
+ return result(true, request_response.body)
23
+ end
24
+
25
+ private
26
+ def place
27
+ %W{
28
+ place=#{ @place || @city || "None given" }
29
+ #{elevation}
30
+ #{coordinates}
31
+ }.join("&")
32
+ end
33
+
34
+ def elevation
35
+ "hh1=#{@z_meters}"
36
+ end
37
+
38
+ def coordinates
39
+ %W{
40
+ xx0=#{ sign_of(@long) }
41
+ xx1=#{ @long.abs }
42
+ xx2=#{ @long_minutes }
43
+ xx3=#{ @long_seconds }
44
+ yy1=#{ @lat.abs }
45
+ yy2=#{ @lat_minutes }
46
+ yy3=#{ @lat_seconds }
47
+ yy0=#{ sign_of(@lat) }
48
+ }.join("&")
49
+ end
50
+
51
+ def sign_of(int)
52
+ int.zero? ? int.next : int / int.abs
53
+ end
54
+
55
+ def request_body
56
+ %W{
57
+ FFX=2
58
+ #{place}
59
+ xxecl=#{USNO::Eclipse::Solar::Eclipses.fetch(@date)}
60
+ ZZZ=END
61
+ }.join("&")
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'usno/eclipse/solar/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "usno-eclipse-solar"
8
+ spec.version = USNO::Eclipse::Solar::VERSION
9
+ spec.authors = ["Ryan T. Hosford"]
10
+ spec.email = ["tad.hosford@gmail.com"]
11
+ spec.description = %q{Obtain the circumstances of recent and upcoming solar eclipses for any location}
12
+ spec.summary = %q{}
13
+ spec.homepage = "http://ea.rthbound.com/usno"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "pay_dirt"
22
+ spec.add_development_dependency "bundler", "~> 1.3"
23
+ spec.add_development_dependency "rake"
24
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: usno-eclipse-solar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ryan T. Hosford
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pay_dirt
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
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
+ description: Obtain the circumstances of recent and upcoming solar eclipses for any
56
+ location
57
+ email:
58
+ - tad.hosford@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .gitignore
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - lib/usno/eclipse/solar.rb
69
+ - lib/usno/eclipse/solar/data.rb
70
+ - lib/usno/eclipse/solar/eclipses.rb
71
+ - lib/usno/eclipse/solar/request.rb
72
+ - lib/usno/eclipse/solar/states.rb
73
+ - lib/usno/eclipse/solar/us_request.rb
74
+ - lib/usno/eclipse/solar/version.rb
75
+ - lib/usno/eclipse/solar/worldwide_request.rb
76
+ - usno-eclipse-solar.gemspec
77
+ homepage: http://ea.rthbound.com/usno
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.0.3
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: ''
101
+ test_files: []