lunartic 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +54 -0
- data/Rakefile +6 -0
- data/lib/lunartic.rb +15 -0
- data/lib/lunartic/moon.rb +48 -0
- data/lib/lunartic/version.rb +3 -0
- data/lunartic.gemspec +22 -0
- data/spec/fixtures/moon.yml +69 -0
- data/spec/lunartic_spec.rb +27 -0
- data/spec/moon_spec.rb +41 -0
- data/spec/spec_helper.rb +24 -0
- metadata +79 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Brian O'Keefe
|
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,54 @@
|
|
1
|
+
# Lunartic
|
2
|
+
|
3
|
+
Calculate the approximate phase of the moon on a given date.
|
4
|
+
|
5
|
+
Note: Calculations are currently *very* approximate and will be improved shortly.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'lunartic'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install lunartic
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
You can get the `day` (day within a cycle, 0..28), `percent_full` (0..1), and `phase` (a symbol) of the moon on a given day like so:
|
24
|
+
|
25
|
+
~~~ ruby
|
26
|
+
irb(main):001:0> require 'lunartic'
|
27
|
+
=> true
|
28
|
+
|
29
|
+
# get moon data for today
|
30
|
+
irb(main):002:0> moon = Lunartic.now
|
31
|
+
=> #<Lunartic::Moon:0x007fa5028e4dc0 @date=#<Date: 2014-06-25 ((2456834j,0s,0n),+0s,2299161j)>>
|
32
|
+
irb(main):003:0> moon.day
|
33
|
+
=> 27
|
34
|
+
irb(main):004:0> moon.phase
|
35
|
+
=> :waning_crescent
|
36
|
+
irb(main):005:0> moon.percent_full
|
37
|
+
=> 0.17138763236974325
|
38
|
+
|
39
|
+
# or, get moon data for a given Date
|
40
|
+
irb(main):006:0> Lunartic.on_date(Date.new(1989, 12, 28)).phase
|
41
|
+
=> :new
|
42
|
+
~~~
|
43
|
+
|
44
|
+
## Testing
|
45
|
+
|
46
|
+
$ rake spec
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
1. Fork it
|
51
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
52
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
53
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
54
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/lunartic.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
module Lunartic
|
2
|
+
class Moon
|
3
|
+
attr_reader :date
|
4
|
+
|
5
|
+
# TODO: we can achieve greater accuracy by adding more
|
6
|
+
# known new moon dates and using the closest one
|
7
|
+
KNOWN_NEW_MOON = Date.new 1900, 1, 1
|
8
|
+
|
9
|
+
SYNODIC_MONTH = 29.530588853
|
10
|
+
HALF_SYNODIC_MONTH = 29.530588853 / 2
|
11
|
+
SYNODIC_DAY = 1 / 29.530588853
|
12
|
+
|
13
|
+
def initialize(date)
|
14
|
+
@date = date
|
15
|
+
end
|
16
|
+
|
17
|
+
def day
|
18
|
+
day = ((@date.jd - KNOWN_NEW_MOON.jd) % SYNODIC_MONTH).floor
|
19
|
+
return 0 if day >= SYNODIC_MONTH.floor
|
20
|
+
day
|
21
|
+
end
|
22
|
+
|
23
|
+
def percent_full
|
24
|
+
(HALF_SYNODIC_MONTH - (day - HALF_SYNODIC_MONTH).abs) / HALF_SYNODIC_MONTH
|
25
|
+
end
|
26
|
+
|
27
|
+
def phase
|
28
|
+
case day
|
29
|
+
when 0
|
30
|
+
:new
|
31
|
+
when 1..6
|
32
|
+
:waxing_crescent
|
33
|
+
when 7
|
34
|
+
:first_quarter
|
35
|
+
when 8..14
|
36
|
+
:waxing_gibbous
|
37
|
+
when 15
|
38
|
+
:full
|
39
|
+
when 16..21
|
40
|
+
:waning_gibbous
|
41
|
+
when 22
|
42
|
+
:last_quarter
|
43
|
+
when 23..28
|
44
|
+
:waning_crescent
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lunartic.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'lunartic/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = 'lunartic'
|
8
|
+
gem.version = Lunartic::VERSION
|
9
|
+
gem.authors = ["Brian O'Keefe"]
|
10
|
+
gem.email = ['brian@bokstuff.com']
|
11
|
+
gem.summary = %q{Calculate the approximate phase of the moon on a given date}
|
12
|
+
gem.description = gem.summary
|
13
|
+
gem.homepage = 'https://github.com/brianokeefe/lunartic'
|
14
|
+
gem.license = 'MIT'
|
15
|
+
|
16
|
+
gem.files = `git ls-files`.split($/)
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
gem.require_paths = ['lib']
|
20
|
+
|
21
|
+
gem.add_development_dependency 'rspec', '~> 3.0.0'
|
22
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
- date_year: 1989
|
2
|
+
date_month: 12
|
3
|
+
date_day: 27
|
4
|
+
day: 28
|
5
|
+
phase: :waning_crescent
|
6
|
+
percent_full: 0.10366124838343745
|
7
|
+
|
8
|
+
- date_year: 1989
|
9
|
+
date_month: 12
|
10
|
+
date_day: 28
|
11
|
+
day: 0
|
12
|
+
phase: :new
|
13
|
+
percent_full: 0.0
|
14
|
+
|
15
|
+
- date_year: 1989
|
16
|
+
date_month: 12
|
17
|
+
date_day: 31
|
18
|
+
day: 3
|
19
|
+
phase: :waxing_crescent
|
20
|
+
percent_full: 0.20317915195891742
|
21
|
+
|
22
|
+
- date_year: 1990
|
23
|
+
date_month: 1
|
24
|
+
date_day: 4
|
25
|
+
day: 7
|
26
|
+
phase: :first_quarter
|
27
|
+
percent_full: 0.47408468790414066
|
28
|
+
|
29
|
+
- date_year: 1990
|
30
|
+
date_month: 1
|
31
|
+
date_day: 7
|
32
|
+
day: 10
|
33
|
+
phase: :waxing_gibbous
|
34
|
+
percent_full: 0.677263839863058
|
35
|
+
|
36
|
+
- date_year: 1990
|
37
|
+
date_month: 1
|
38
|
+
date_day: 12
|
39
|
+
day: 15
|
40
|
+
phase: :full
|
41
|
+
percent_full: 0.9841042402054129
|
42
|
+
|
43
|
+
- date_year: 1990
|
44
|
+
date_month: 1
|
45
|
+
date_day: 15
|
46
|
+
day: 18
|
47
|
+
phase: :waning_gibbous
|
48
|
+
percent_full: 0.7809250882464955
|
49
|
+
|
50
|
+
- date_year: 1990
|
51
|
+
date_month: 1
|
52
|
+
date_day: 19
|
53
|
+
day: 22
|
54
|
+
phase: :last_quarter
|
55
|
+
percent_full: 0.5100195523012723
|
56
|
+
|
57
|
+
- date_year: 1990
|
58
|
+
date_month: 1
|
59
|
+
date_day: 22
|
60
|
+
day: 25
|
61
|
+
phase: :waning_crescent
|
62
|
+
percent_full: 0.3068404003423549
|
63
|
+
|
64
|
+
- date_year: 1990
|
65
|
+
date_month: 1
|
66
|
+
date_day: 26
|
67
|
+
day: 0
|
68
|
+
phase: :new
|
69
|
+
percent_full: 0.0
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Lunartic do
|
4
|
+
describe '.now' do
|
5
|
+
let(:subject) { Lunartic.now }
|
6
|
+
|
7
|
+
it 'should return a Lunartic::Moon' do
|
8
|
+
expect(subject).to be_a Lunartic::Moon
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should create a Lunartic::Moon using today's date" do
|
12
|
+
expect(subject.day).to eql Lunartic::Moon.new(Date.today).day
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '.on_date' do
|
17
|
+
let(:subject) { Lunartic.on_date(Date.new(1989, 12, 28)) }
|
18
|
+
|
19
|
+
it 'should return a Lunartic::Moon' do
|
20
|
+
expect(subject).to be_a Lunartic::Moon
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should create a Lunartic::Moon using the specified date' do
|
24
|
+
expect(subject.day).to eql Lunartic::Moon.new(Date.new(1989, 12, 28)).day
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/spec/moon_spec.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Lunartic::Moon do
|
4
|
+
let(:subject) { Lunartic::Moon.new(Date.new(1989, 12, 28)) }
|
5
|
+
|
6
|
+
describe '#initialize' do
|
7
|
+
it 'should return a Lunartic::Moon' do
|
8
|
+
expect(subject).to be_a Lunartic::Moon
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#day' do
|
13
|
+
it 'should return a fixnum' do
|
14
|
+
expect(subject.day).to be_a Fixnum
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should return the correct cycle day for the given date' do
|
18
|
+
test_method_against_fixtures :day
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#percent_full' do
|
23
|
+
it 'should return a float' do
|
24
|
+
expect(subject.percent_full).to be_a Float
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should return the correct percentage full for the given date' do
|
28
|
+
test_method_against_fixtures :percent_full
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#phase' do
|
33
|
+
it 'should return a symbol' do
|
34
|
+
expect(subject.phase).to be_a Symbol
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should return the correct moon phase for a given date' do
|
38
|
+
test_method_against_fixtures :phase
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'lunartic'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
config.color = true
|
6
|
+
config.tty = true
|
7
|
+
config.formatter = :documentation
|
8
|
+
end
|
9
|
+
|
10
|
+
FIXTURES = YAML.load_file("#{File.dirname __FILE__}/fixtures/moon.yml").map do |obj|
|
11
|
+
sym_hash = {}
|
12
|
+
obj.each_pair do |k,v|
|
13
|
+
sym_hash[k.to_sym] = v
|
14
|
+
end
|
15
|
+
sym_hash
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_method_against_fixtures(method)
|
19
|
+
FIXTURES.each do |known|
|
20
|
+
date = Date.new(known[:date_year], known[:date_month], known[:date_day])
|
21
|
+
moon = Lunartic::Moon.new date
|
22
|
+
expect(moon.send(method)).to eql known[method]
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lunartic
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Brian O'Keefe
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-06-25 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.0.0
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.0.0
|
30
|
+
description: Calculate the approximate phase of the moon on a given date
|
31
|
+
email:
|
32
|
+
- brian@bokstuff.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- LICENSE.txt
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- lib/lunartic.rb
|
43
|
+
- lib/lunartic/moon.rb
|
44
|
+
- lib/lunartic/version.rb
|
45
|
+
- lunartic.gemspec
|
46
|
+
- spec/fixtures/moon.yml
|
47
|
+
- spec/lunartic_spec.rb
|
48
|
+
- spec/moon_spec.rb
|
49
|
+
- spec/spec_helper.rb
|
50
|
+
homepage: https://github.com/brianokeefe/lunartic
|
51
|
+
licenses:
|
52
|
+
- MIT
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 1.8.23
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: Calculate the approximate phase of the moon on a given date
|
75
|
+
test_files:
|
76
|
+
- spec/fixtures/moon.yml
|
77
|
+
- spec/lunartic_spec.rb
|
78
|
+
- spec/moon_spec.rb
|
79
|
+
- spec/spec_helper.rb
|