solaar 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -1
- data/HISTORY.md +7 -1
- data/README.md +4 -9
- data/lib/solaar.rb +1 -1
- data/lib/solaar/terms.rb +5 -6
- data/test/helper.rb +1 -0
- data/test/test_solaar.rb +54 -2
- metadata +2 -2
data/Gemfile
CHANGED
data/HISTORY.md
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Solaar
|
2
|
-
|
2
|
+
==========
|
3
3
|
|
4
|
-
A Ruby gem to calculate the 24
|
4
|
+
A Ruby gem to calculate the 24 solar terms ("ki" in Japanese) until 2099.
|
5
5
|
|
6
6
|
Installation
|
7
7
|
-------------
|
@@ -49,20 +49,15 @@ Usage
|
|
49
49
|
=> [{:date=>"2015-03-06", :ja=>"啓蟄", :en=>"Awakening of insects"},
|
50
50
|
{:date=>"2015-03-21", :ja=>"春分", :en=>"Vernal equinox"}]
|
51
51
|
|
52
|
-
pp solaar.calc(year:
|
52
|
+
pp solaar.calc(year: 2012, term: "春分")
|
53
53
|
=> [{:date=>"2012-03-20", :ja=>"春分", :en=>"Vernal equinox"}]
|
54
54
|
|
55
55
|
pp solaar.calc(year: 2100)
|
56
56
|
=> "Unable to calculate with the given year"
|
57
57
|
|
58
58
|
|
59
|
-
TODO
|
60
|
-
---------
|
61
|
-
|
62
|
-
* Write test
|
63
|
-
|
64
59
|
Author
|
65
|
-
|
60
|
+
---------
|
66
61
|
|
67
62
|
azukiwasher, http://twitter.com/azukiwasher, azukiwasher AT higanworks.com
|
68
63
|
|
data/lib/solaar.rb
CHANGED
data/lib/solaar/terms.rb
CHANGED
@@ -24,9 +24,9 @@ module Solaar
|
|
24
24
|
{m: 10, day: 24.2487, adj: 0.242328, ja: '霜降', en: 'Frost descent'},
|
25
25
|
{m: 11, day: 8.2396, adj: 0.242469, ja: '立冬', en: 'Start of winter'},
|
26
26
|
{m: 11, day: 23.1189, adj: 0.242592, ja: '小雪', en: 'Minor snow'},
|
27
|
-
{m: 12, day: 7.9152, adj: 0.242689, ja: '大雪', en: 'Major
|
27
|
+
{m: 12, day: 7.9152, adj: 0.242689, ja: '大雪', en: 'Major snow'},
|
28
28
|
{m: 12, day: 22.6587, adj: 0.242752, ja: '冬至', en: 'Winter solstice'}
|
29
|
-
|
29
|
+
]
|
30
30
|
|
31
31
|
class Terms
|
32
32
|
|
@@ -37,11 +37,10 @@ module Solaar
|
|
37
37
|
def calc(*args)
|
38
38
|
opts = args.last.is_a?(Hash) ? args.pop : {}
|
39
39
|
opts.merge!(year: self.year) if !opts.key?(:year)
|
40
|
-
return "Unable to calculate with
|
40
|
+
return "Unable to calculate with given year" if opts[:year].to_i > 2099
|
41
41
|
|
42
42
|
if opts.key?(:month)
|
43
|
-
|
44
|
-
s = m*2-2
|
43
|
+
s = opts[:month].to_i*2-2
|
45
44
|
self.solaarterms(opts, [s, s+1])
|
46
45
|
else
|
47
46
|
self.solaarterms(opts, nil)
|
@@ -63,7 +62,7 @@ module Solaar
|
|
63
62
|
|
64
63
|
def formula(opts={})
|
65
64
|
y = @year = opts[:year]
|
66
|
-
opts.key?(:month) ?
|
65
|
+
month = opts.key?(:month) ? opts[:month].to_i : opts[:m]
|
67
66
|
|
68
67
|
y = month <= 2 ? y - 1 : y
|
69
68
|
day = opts[:day] + opts[:adj] * (y - 1900) - ((y - 1900) / 4)
|
data/test/helper.rb
CHANGED
data/test/test_solaar.rb
CHANGED
@@ -1,8 +1,60 @@
|
|
1
|
+
# -*- encoding: UTF-8 -*-
|
1
2
|
require 'helper'
|
2
3
|
|
3
4
|
class TestSolaar < Test::Unit::TestCase
|
4
5
|
|
5
|
-
|
6
|
-
|
6
|
+
context "a solaar" do
|
7
|
+
setup do
|
8
|
+
@solaar = Solaar::Terms.new
|
9
|
+
end
|
10
|
+
|
11
|
+
should "not calculate with give year" do
|
12
|
+
assert_equal "Unable to calculate with given year", @solaar.calc(year: 2100)
|
13
|
+
end
|
14
|
+
|
15
|
+
should "calculate a date with a year and a month" do
|
16
|
+
assert_equal "2012-03-05", @solaar.calc(year: 2012, month: 3).first[:date]
|
17
|
+
assert_equal "啓蟄", @solaar.calc(year: 2012, month: 3).first[:ja]
|
18
|
+
assert_equal "Awakening of insects", @solaar.calc(year: 2012, month: 3).first[:en]
|
19
|
+
assert_equal "2012-03-20", @solaar.calc(year: 2012, month: 3).last[:date]
|
20
|
+
assert_equal "春分", @solaar.calc(year: 2012, month: 3).last[:ja]
|
21
|
+
assert_equal "Vernal equinox", @solaar.calc(year: 2012, month: 3).last[:en]
|
22
|
+
end
|
23
|
+
|
24
|
+
should "calculate all dates for the given year" do
|
25
|
+
assert_equal 24, @solaar.calc(year: 2015).size
|
26
|
+
assert_equal "2015-01-06", @solaar.calc(year: 2015).first[:date]
|
27
|
+
assert_equal "小寒", @solaar.calc(year: 2015).first[:ja]
|
28
|
+
assert_equal "Minor cold", @solaar.calc(year: 2015).first[:en]
|
29
|
+
assert_equal "2015-12-22", @solaar.calc(year: 2015).last[:date]
|
30
|
+
assert_equal "冬至", @solaar.calc(year: 2015).last[:ja]
|
31
|
+
assert_equal "Winter solstice", @solaar.calc(year: 2015).last[:en]
|
32
|
+
end
|
33
|
+
|
34
|
+
should "calculate all dates for this year without year parameter" do
|
35
|
+
assert_equal 24, @solaar.calc.size
|
36
|
+
assert_equal "#{Time.now.year}", @solaar.calc.first[:date].split(/-/).first
|
37
|
+
assert_equal "#{Time.now.year}", @solaar.calc.first[:date].split(/-/).first
|
38
|
+
end
|
39
|
+
|
40
|
+
should "calculate all dates for the year and given month without year parameter" do
|
41
|
+
assert_equal 2, @solaar.calc(month: 3).size
|
42
|
+
assert_equal "#{Time.now.year}", @solaar.calc(month: 3).first[:date].split(/-/).first
|
43
|
+
assert_equal "#{Time.now.year}", @solaar.calc(month: 3).last[:date].split(/-/).first
|
44
|
+
end
|
45
|
+
|
46
|
+
should "calculate all dates for the year and given term without year parameter" do
|
47
|
+
assert_equal 1, @solaar.calc(term: '春分').size
|
48
|
+
assert_equal "#{Time.now.year}", @solaar.calc(term: "春分").first[:date].split(/-/).first
|
49
|
+
assert_equal "春分", @solaar.calc(term: "春分").last[:ja]
|
50
|
+
assert_equal "Vernal equinox", @solaar.calc(term: "春分").last[:en]
|
51
|
+
end
|
52
|
+
|
53
|
+
should "calculate all dates for the year and given term with a year parameter" do
|
54
|
+
assert_equal 1, @solaar.calc(year: 2015, term: '春分').size
|
55
|
+
assert_equal "2015", @solaar.calc(term: "春分").first[:date].split(/-/).first
|
56
|
+
assert_equal "春分", @solaar.calc(term: "春分").last[:ja]
|
57
|
+
assert_equal "Vernal equinox", @solaar.calc(term: "春分").last[:en]
|
58
|
+
end
|
7
59
|
end
|
8
60
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solaar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-02-
|
12
|
+
date: 2012-02-26 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Calculates the 24 solar terms until 2099
|
15
15
|
email:
|