solaar 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
@@ -0,0 +1,53 @@
1
+ # rcov generated
2
+ coverage
3
+ coverage.data
4
+
5
+ # rdoc generated
6
+ rdoc
7
+
8
+ # yard generated
9
+ doc
10
+ .yardoc
11
+
12
+ # bundler
13
+ .bundle
14
+
15
+ # jeweler generated
16
+ pkg
17
+
18
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
19
+ #
20
+ # * Create a file at ~/.gitignore
21
+ # * Include files you want ignored
22
+ # * Run: git config --global core.excludesfile ~/.gitignore
23
+ #
24
+ # After doing this, these files will be ignored in all your git projects,
25
+ # saving you from having to 'pollute' every project you touch with them
26
+ #
27
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
28
+ #
29
+ # For MacOS:
30
+ #
31
+ .DS_Store
32
+
33
+ # For TextMate
34
+ #*.tmproj
35
+ #tmtags
36
+
37
+ # For emacs:
38
+ #*~
39
+ #\#*
40
+ #.\#*
41
+
42
+ # For vim:
43
+ *.swp
44
+
45
+ # For redcar:
46
+ #.redcar
47
+
48
+ # For rubinius:
49
+ #*.rbc
50
+
51
+ # For Gemfile.lock
52
+ *.gem
53
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+ gemspec
3
+
4
+ gem 'simplecov', :require => false, :group => :test
@@ -0,0 +1,7 @@
1
+ Changes
2
+ ================
3
+
4
+ 0.1.0
5
+ -----
6
+
7
+ - Initial release
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 azukiwasher
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,72 @@
1
+ Solaar
2
+ ===========
3
+
4
+ A Ruby gem to calculate the 24 solaar terms ("ki" in Japanese) until 2099.
5
+
6
+ Installation
7
+ -------------
8
+ gem install solaar
9
+
10
+
11
+ Usage
12
+ ---------
13
+ require 'solaar'
14
+ require 'pp'
15
+
16
+ solaar = Solaar::Terms.new
17
+
18
+ pp solaar.calc(year: 2012)
19
+ => [{:date=>"2012-01-06", :ja=>"小寒", :en=>"Minor cold"},
20
+ {:date=>"2012-01-21", :ja=>"大寒", :en=>"Major cold"},
21
+ {:date=>"2012-02-04", :ja=>"立春", :en=>"Start of spring"},
22
+ {:date=>"2012-02-19", :ja=>"雨水", :en=>"Rain water"},
23
+ {:date=>"2012-03-05", :ja=>"啓蟄", :en=>"Awakening of insects"},
24
+ {:date=>"2012-03-20", :ja=>"春分", :en=>"Vernal equinox"},
25
+ {:date=>"2012-04-04", :ja=>"清明", :en=>"Clear and bright"},
26
+ {:date=>"2012-04-20", :ja=>"穀雨", :en=>"Grain rainain"},
27
+ {:date=>"2012-05-05", :ja=>"立夏", :en=>"Start of summer"},
28
+ {:date=>"2012-05-21", :ja=>"小満", :en=>"Grain full"},
29
+ {:date=>"2012-06-05", :ja=>"芒種", :en=>"Grain in ear"},
30
+ {:date=>"2012-06-21", :ja=>"夏至", :en=>"Summer solstice"},
31
+ {:date=>"2012-07-07", :ja=>"小暑", :en=>"Minor heat"},
32
+ {:date=>"2012-07-22", :ja=>"大暑", :en=>"Major heat"},
33
+ {:date=>"2012-08-07", :ja=>"立秋", :en=>"Start of autumn"},
34
+ {:date=>"2012-08-23", :ja=>"処暑", :en=>"Limit of heat"},
35
+ {:date=>"2012-09-07", :ja=>"白露", :en=>"White dew"},
36
+ {:date=>"2012-09-22", :ja=>"秋分", :en=>"Autumnal equinox"},
37
+ {:date=>"2012-10-08", :ja=>"寒露", :en=>"Cold dew"},
38
+ {:date=>"2012-10-23", :ja=>"霜降", :en=>"Frost descent"},
39
+ {:date=>"2012-11-07", :ja=>"立冬", :en=>"Start of winter"},
40
+ {:date=>"2012-11-22", :ja=>"小雪", :en=>"Minor snow"},
41
+ {:date=>"2012-12-07", :ja=>"大雪", :en=>"Major snow"},
42
+ {:date=>"2012-12-21", :ja=>"冬至", :en=>"Winter solstice"}]
43
+
44
+ pp solaar.calc(year: 2012, month: 3)
45
+ => [{:date=>"2012-03-05", :ja=>"啓蟄", :en=>"Awakening of insects"},
46
+ {:date=>"2012-03-20", :ja=>"春分", :en=>"Vernal equinox"}]
47
+
48
+ pp solaar.calc(year: 2015, month: 3)
49
+ => [{:date=>"2015-03-06", :ja=>"啓蟄", :en=>"Awakening of insects"},
50
+ {:date=>"2015-03-21", :ja=>"春分", :en=>"Vernal equinox"}]
51
+
52
+ pp solaar.calc(year: 2100, term: "春分")
53
+ => [{:date=>"2012-03-20", :ja=>"春分", :en=>"Vernal equinox"}]
54
+
55
+ pp solaar.calc(year: 2100)
56
+ => "Unable to calculate with the given year"
57
+
58
+
59
+ TODO
60
+ ---------
61
+
62
+ * Write test
63
+
64
+ Author
65
+ ==========
66
+
67
+ azukiwasher, http://twitter.com/azukiwasher, azukiwasher AT higanworks.com
68
+
69
+ Copyright
70
+ ----------
71
+
72
+ Copyright (c) 2012 azukiwasher. See LICENSE for details.
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rake/testtask'
4
+ Rake::TestTask.new(:test) do |test|
5
+ test.libs << 'lib' << 'test'
6
+ test.pattern = 'test/**/test_*.rb'
7
+ test.verbose = true
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,6 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+ require 'solaar/terms'
3
+
4
+ module Solaar
5
+ VERSION = Version = "0.1.0"
6
+ end
@@ -0,0 +1,78 @@
1
+ # encoding: UTF-8
2
+
3
+ module Solaar
4
+ Table = TABLE = [
5
+ {m: 1, day: 6.3811, adj: 0.242778, ja: '小寒', en: 'Minor cold'},
6
+ {m: 1, day: 21.1046, adj: 0.242765, ja: '大寒', en: 'Major cold'},
7
+ {m: 2, day: 4.8693, adj: 0.242713, ja: '立春', en: 'Start of spring'},
8
+ {m: 2, day: 19.7062, adj: 0.242627, ja: '雨水', en: 'Rain water'},
9
+ {m: 3, day: 6.3968, adj: 0.242512, ja: '啓蟄', en: 'Awakening of insects'},
10
+ {m: 3, day: 21.4471, adj: 0.242377, ja: '春分', en: 'Vernal equinox'},
11
+ {m: 4, day: 5.628, adj: 0.242231, ja: '清明', en: 'Clear and bright'},
12
+ {m: 4, day: 20.9375, adj: 0.242083, ja: '穀雨', en: 'Grain rainain'},
13
+ {m: 5, day: 6.3771, adj: 0.241945, ja: '立夏', en: 'Start of summer'},
14
+ {m: 5, day: 21.93, adj: 0.241825, ja: '小満', en: 'Grain full'},
15
+ {m: 6, day: 6.5733, adj: 0.241731, ja: '芒種', en: 'Grain in ear'},
16
+ {m: 6, day: 22.2747, adj: 0.241669, ja: '夏至', en: 'Summer solstice'},
17
+ {m: 7, day: 8.0091, adj: 0.241642, ja: '小暑', en: 'Minor heat'},
18
+ {m: 7, day: 23.7317, adj: 0.241654, ja: '大暑', en: 'Major heat'},
19
+ {m: 8, day: 8.4102, adj: 0.241703, ja: '立秋', en: 'Start of autumn'},
20
+ {m: 8, day: 24.0125, adj: 0.241786, ja: '処暑', en: 'Limit of heat'},
21
+ {m: 9, day: 8.5186, adj: 0.241898, ja: '白露', en: 'White dew'},
22
+ {m: 9, day: 23.8896, adj: 0.242032, ja: '秋分', en: 'Autumnal equinox'},
23
+ {m: 10, day: 9.1414, adj: 0.242179, ja: '寒露', en: 'Cold dew'},
24
+ {m: 10, day: 24.2487, adj: 0.242328, ja: '霜降', en: 'Frost descent'},
25
+ {m: 11, day: 8.2396, adj: 0.242469, ja: '立冬', en: 'Start of winter'},
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 snow'},
28
+ {m: 12, day: 22.6587, adj: 0.242752, ja: '冬至', en: 'Winter solstice'}
29
+ ]
30
+
31
+ class Terms
32
+
33
+ def initialize
34
+ @solaarterms = Solaar::Table
35
+ end
36
+
37
+ def calc(*args)
38
+ opts = args.last.is_a?(Hash) ? args.pop : {}
39
+ opts.merge!(year: self.year) if !opts.key?(:year)
40
+ return "Unable to calculate with the given year" if opts[:year].to_i > 2099
41
+
42
+ if opts.key?(:month)
43
+ m = opts[:month].to_i
44
+ s = m*2-2
45
+ self.solaarterms(opts, [s, s+1])
46
+ else
47
+ self.solaarterms(opts, nil)
48
+ end
49
+
50
+ @terms
51
+ end
52
+
53
+ def solaarterms(opts={}, range=nil)
54
+ @terms = []
55
+ s, e = range.nil? ? [0,-1] : range
56
+
57
+ if opts.key?(:term)
58
+ @solaarterms[s..e].each{ |t| @terms << self.formula(opts.merge!(t)) if opts[:term] == t[:ja] }
59
+ else
60
+ @solaarterms[s..e].each{ |t| @terms << self.formula(opts.merge!(t)) }
61
+ end
62
+ end
63
+
64
+ def formula(opts={})
65
+ y = @year = opts[:year]
66
+ opts.key?(:month) ? month = opts[:month].to_i : month = opts[:m]
67
+
68
+ y = month <= 2 ? y - 1 : y
69
+ day = opts[:day] + opts[:adj] * (y - 1900) - ((y - 1900) / 4)
70
+ Hash[date: Time.new(@year, month, day).strftime("%F"), ja: opts[:ja], en: opts[:en]]
71
+ end
72
+
73
+ def year
74
+ @year ||= Time.now.year
75
+ end
76
+
77
+ end
78
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require 'solaar'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "solaar"
7
+ s.version = Solaar::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["azukiwasher"]
10
+ s.email = ["azukiwasher@higanworks.com"]
11
+ s.homepage = "http://github.com/azukiwasher/solaar"
12
+ s.summary = s.description = %q(Calculates the 24 solar terms until 2099)
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- test/*`.split("\n")
16
+ s.require_paths = ["lib"]
17
+
18
+ s.rubyforge_project = "solaar"
19
+ end
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ begin
5
+ Bundler.setup(:default, :development)
6
+ rescue Bundler::BundlerError => e
7
+ $stderr.puts e.message
8
+ $stderr.puts "Run `bundle install` to install missing gems"
9
+ exit e.status_code
10
+ end
11
+
12
+ require 'test/unit'
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+
16
+ require 'solaar'
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,8 @@
1
+ require 'helper'
2
+
3
+ class TestSolaar < Test::Unit::TestCase
4
+
5
+ def test_solar_terms_with_given_year
6
+ true
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: solaar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - azukiwasher
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-24 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Calculates the 24 solar terms until 2099
15
+ email:
16
+ - azukiwasher@higanworks.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .document
22
+ - .gitignore
23
+ - Gemfile
24
+ - HISTORY.md
25
+ - LICENSE
26
+ - README.md
27
+ - Rakefile
28
+ - lib/solaar.rb
29
+ - lib/solaar/terms.rb
30
+ - solaar.gemspec
31
+ - test/helper.rb
32
+ - test/test_solaar.rb
33
+ homepage: http://github.com/azukiwasher/solaar
34
+ licenses: []
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubyforge_project: solaar
53
+ rubygems_version: 1.8.15
54
+ signing_key:
55
+ specification_version: 3
56
+ summary: Calculates the 24 solar terms until 2099
57
+ test_files:
58
+ - test/helper.rb
59
+ - test/test_solaar.rb