solaar 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 96a05f47cecbbcf5819cc3339bdd744a3d37dcd8
4
+ data.tar.gz: f48d6c69a6270ecd1ac8c418a90c11b6ad377ad2
5
+ SHA512:
6
+ metadata.gz: 72d7111940c4a1ca1a372331b061d51b3e9fea123b3acd3a7b893d3cd1890c00e9179d1f3fd8f9e8e2120b18f04fa4d1f3c999d47a59dbcb7b71e5fad92cf6ac
7
+ data.tar.gz: 00942602a935b1d470d3cfd429f2ff66a3b9aa7e90df4f96eff36c2603b0e3316f80c264c4cbdf4ac2299bc2ccb5bef9cc8d955f2afd2ab25d9033f38cd9f27d
data/.gitignore CHANGED
@@ -50,4 +50,3 @@ pkg
50
50
 
51
51
  # For Gemfile.lock
52
52
  *.gem
53
- Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile CHANGED
@@ -1,7 +1,4 @@
1
1
  source "http://rubygems.org"
2
+ ruby "2.1.1"
3
+ gem 'rspec'
2
4
  gemspec
3
-
4
- group :test do
5
- gem 'simplecov', :require => false
6
- gem 'shoulda'
7
- end
@@ -0,0 +1,57 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ solaar (0.2.0)
5
+ oj
6
+ sinatra
7
+ sinatra-contrib
8
+ thin
9
+
10
+ GEM
11
+ remote: http://rubygems.org/
12
+ specs:
13
+ backports (3.6.0)
14
+ daemons (1.1.9)
15
+ diff-lcs (1.2.5)
16
+ eventmachine (1.0.3)
17
+ multi_json (1.9.2)
18
+ oj (2.7.2)
19
+ rack (1.5.2)
20
+ rack-protection (1.5.3)
21
+ rack
22
+ rack-test (0.6.2)
23
+ rack (>= 1.0)
24
+ rake (10.2.2)
25
+ rspec (2.14.1)
26
+ rspec-core (~> 2.14.0)
27
+ rspec-expectations (~> 2.14.0)
28
+ rspec-mocks (~> 2.14.0)
29
+ rspec-core (2.14.8)
30
+ rspec-expectations (2.14.5)
31
+ diff-lcs (>= 1.1.3, < 2.0)
32
+ rspec-mocks (2.14.6)
33
+ sinatra (1.4.5)
34
+ rack (~> 1.4)
35
+ rack-protection (~> 1.4)
36
+ tilt (~> 1.3, >= 1.3.4)
37
+ sinatra-contrib (1.4.2)
38
+ backports (>= 2.0)
39
+ multi_json
40
+ rack-protection
41
+ rack-test
42
+ sinatra (~> 1.4.0)
43
+ tilt (~> 1.3)
44
+ thin (1.6.2)
45
+ daemons (>= 1.0.9)
46
+ eventmachine (>= 1.0.0)
47
+ rack (>= 1.0.0)
48
+ tilt (1.4.1)
49
+
50
+ PLATFORMS
51
+ ruby
52
+
53
+ DEPENDENCIES
54
+ bundler
55
+ rake
56
+ rspec
57
+ solaar!
@@ -0,0 +1 @@
1
+ web: bundle exec bin/solaar
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  Solaar
2
2
  ==========
3
3
 
4
- A Ruby gem to calculate the 24 solar terms ("ki" in Japanese) until 2099.
4
+ A Ruby gem to calculate the 24 solar terms ("24節気" in Japanese) until 2099.
5
5
 
6
6
  Installation
7
7
  -------------
@@ -13,10 +13,10 @@ Usage
13
13
  require 'solaar'
14
14
  require 'pp'
15
15
 
16
- solaar = Solaar::Terms.new
16
+ solaar = Solaar::Term.new
17
17
 
18
18
  pp solaar.calc(year: 2012)
19
- => [{:date=>"2012-01-06", :ja=>"小寒", :en=>"Minor cold"},
19
+ #=> [{:date=>"2012-01-06", :ja=>"小寒", :en=>"Minor cold"},
20
20
  {:date=>"2012-01-21", :ja=>"大寒", :en=>"Major cold"},
21
21
  {:date=>"2012-02-04", :ja=>"立春", :en=>"Start of spring"},
22
22
  {:date=>"2012-02-19", :ja=>"雨水", :en=>"Rain water"},
@@ -41,19 +41,19 @@ Usage
41
41
  {:date=>"2012-12-07", :ja=>"大雪", :en=>"Major snow"},
42
42
  {:date=>"2012-12-21", :ja=>"冬至", :en=>"Winter solstice"}]
43
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"}]
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
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"}]
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
51
 
52
- pp solaar.calc(year: 2012, term: "春分")
53
- => [{:date=>"2012-03-20", :ja=>"春分", :en=>"Vernal equinox"}]
52
+ pp solaar.calc(year: 2012, term: "春分")
53
+ #=> [{:date=>"2012-03-20", :ja=>"春分", :en=>"Vernal equinox"}]
54
54
 
55
- pp solaar.calc(year: 2100)
56
- => "Unable to calculate with the given year"
55
+ pp solaar.calc(year: 2100)
56
+ #=> "Unable to calculate with the given year"
57
57
 
58
58
 
59
59
  Author
data/Rakefile CHANGED
@@ -1,10 +1,5 @@
1
1
  # encoding: utf-8
2
+ require 'rspec/core/rake_task'
2
3
 
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
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task :default => :spec
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'sinatra/base'
4
+ require 'sinatra/json'
5
+ require 'oj'
6
+ require_relative '../lib/solaar'
7
+
8
+ class App < Sinatra::Base
9
+ set :show_exceptions, :after_handler
10
+ solaar = Solaar::Term.new
11
+
12
+ get '/' do
13
+ json solaar.calc
14
+ end
15
+
16
+ get '/:year' do
17
+ year = params[:year].to_i
18
+ json solaar.calc(year: year)
19
+ end
20
+
21
+ get '/:year/:month_or_term' do
22
+ year = params[:year].to_i
23
+ param = params[:month_or_term].to_i
24
+ if param == 0
25
+ json solaar.calc(year: year, term: params[:month_or_term])
26
+ else
27
+ json solaar.calc(year: year, month: param)
28
+ end
29
+ end
30
+
31
+ error Sinatra::NotFound do
32
+ status 404
33
+ json({ error: "Resource not found" })
34
+ end
35
+
36
+ error ArgumentError do
37
+ status 400
38
+ json({ error: env['sinatra.error'].message })
39
+ end
40
+
41
+ error Solaar::Exception::OutOfRange do
42
+ status 400
43
+ json({ error: env['sinatra.error'].message })
44
+ end
45
+ end
46
+
47
+ App.run!
@@ -1,6 +1,3 @@
1
1
  $:.unshift File.dirname(__FILE__)
2
- require 'solaar/terms'
3
-
4
- module Solaar
5
- VERSION = Version = "0.1.1"
6
- end
2
+ require 'solaar/version'
3
+ require 'solaar/term'
@@ -0,0 +1,8 @@
1
+ # encoding: utf-8
2
+
3
+ module Solaar
4
+ class Exception
5
+ class Error < StandardError ; end
6
+ class OutOfRange < Error ; end
7
+ end
8
+ end
@@ -0,0 +1,30 @@
1
+ # encoding: UTF-8
2
+
3
+ module Solaar
4
+ 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
+ end
@@ -0,0 +1,55 @@
1
+ # encoding: UTF-8
2
+ require 'solaar/table'
3
+ require 'solaar/exception'
4
+
5
+ module Solaar
6
+ class Term
7
+ attr_reader :solaar_terms
8
+
9
+ def initialize
10
+ @solaar_terms = Solaar::Table
11
+ end
12
+
13
+ def calc(*args)
14
+ opts = args.last.is_a?(Hash) ? args.pop : {}
15
+ opts.merge!(year: self.year) if !opts.key?(:year)
16
+
17
+ if opts[:year].to_i > 2099 || opts[:year].to_i <= 0
18
+ raise Exception::OutOfRange.new("Unable to calculate")
19
+ end
20
+
21
+ if opts.key?(:month) && (1..12).map.include?(opts[:month].to_i)
22
+ s = opts[:month].to_i*2-2
23
+ solaar_terms(opts, [s, s+1])
24
+ else
25
+ solaar_terms(opts, nil)
26
+ end
27
+
28
+ @terms
29
+ end
30
+
31
+ def solaar_terms(opts={}, range=nil)
32
+ @terms = []
33
+ s, e = range.nil? ? [0,-1] : range
34
+
35
+ if opts.key?(:term)
36
+ @solaar_terms[s..e].each{ |t| @terms << formula(opts.merge!(t)) if opts[:term] == t[:ja] }
37
+ else
38
+ @solaar_terms[s..e].each{ |t| @terms << formula(opts.merge!(t)) }
39
+ end
40
+ end
41
+
42
+ def formula(opts={})
43
+ y = @year = opts[:year]
44
+ month = opts.key?(:month) ? opts[:month].to_i : opts[:m]
45
+
46
+ y = month <= 2 ? y - 1 : y
47
+ day = opts[:day] + opts[:adj] * (y - 1900) - ((y - 1900) / 4)
48
+ Hash[date: Time.new(@year, month, day).strftime("%F"), language: { ja: opts[:ja], en: opts[:en] }]
49
+ end
50
+
51
+ def year
52
+ @year ||= Time.now.year
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,4 @@
1
+ # encoding: utf-8
2
+ module Solaar
3
+ VERSION = Version = "0.2.0"
4
+ end
@@ -1,19 +1,28 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require 'solaar'
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'solaar/version'
4
5
 
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)
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "solaar"
8
+ spec.version = Solaar::VERSION
9
+ spec.authors = ["azukiwasher"]
10
+ spec.email = ["azukiwasher@higanworks.com"]
11
+ spec.description = %q{Calculates the 24 solar terms until 2099}
12
+ spec.summary = %q{Calculates the 24 solar terms until 2099}
13
+ spec.homepage = "http://github.com/azukiwasher/solaar"
14
+ spec.license = "MIT"
13
15
 
14
- s.files = `git ls-files`.split("\n")
15
- s.test_files = `git ls-files -- test/*`.split("\n")
16
- s.require_paths = ["lib"]
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"]
17
20
 
18
- s.rubyforge_project = "solaar"
21
+ spec.add_runtime_dependency "sinatra"
22
+ spec.add_runtime_dependency "sinatra-contrib"
23
+ spec.add_runtime_dependency "thin"
24
+ spec.add_runtime_dependency "oj"
25
+
26
+ spec.add_development_dependency "bundler"
27
+ spec.add_development_dependency "rake"
19
28
  end
@@ -0,0 +1,38 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Solaar::Term do
5
+ let(:solaar) { Solaar::Term.new }
6
+ let(:record) {{ date: "2014-12-07", language: { ja: "大雪", en: "Major snow" }}}
7
+
8
+ describe "#calc" do
9
+ it "returns a collection of terms for this year" do
10
+ expect(solaar.calc.first[:date]).to match /2014/
11
+ end
12
+
13
+ it "returns a collection of terms for the given year" do
14
+ expect(solaar.calc(year: 2014).size).to eql 24
15
+ end
16
+
17
+ it "returns a record for the given year and month" do
18
+ expect(solaar.calc(year: 2014, month: 12).first).to eql record
19
+ end
20
+
21
+ it "returns a record for the given month" do
22
+ expect(solaar.calc(month: 12).size).to eql 2
23
+ expect(solaar.calc(month: 12).first).to eql record
24
+ end
25
+
26
+ it "returns a record for the given month" do
27
+ expect(solaar.calc(term: "大雪").first).to eql record
28
+ end
29
+
30
+ it "raises out of range error" do
31
+ expect{ solaar.calc(year: 2100) }.to raise_error(Solaar::Exception::OutOfRange)
32
+ end
33
+
34
+ it "raises argument error" do
35
+ expect{ solaar.calc(month: 'hoge') }.to raise_error(ArgumentError)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,25 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+
8
+ require 'rspec'
9
+ require 'solaar'
10
+
11
+ RSpec.configure do |config|
12
+ config.treat_symbols_as_metadata_keys_with_true_values = true
13
+ config.run_all_when_everything_filtered = true
14
+ config.filter_run :focus
15
+
16
+ # Run specs in random order to surface order dependencies. If you find an
17
+ # order dependency and want to debug it, you can fix the order by providing
18
+ # the seed, which is printed after each run.
19
+ # --seed 1234
20
+ config.order = 'random'
21
+
22
+ config.expect_with :rspec do |c|
23
+ c.syntax = :expect
24
+ end
25
+ end
metadata CHANGED
@@ -1,59 +1,148 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solaar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
5
- prerelease:
4
+ version: 0.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - azukiwasher
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-02-26 00:00:00.000000000 Z
13
- dependencies: []
11
+ date: 2014-04-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sinatra
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: sinatra-contrib
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: thin
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
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: oj
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: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
14
97
  description: Calculates the 24 solar terms until 2099
15
98
  email:
16
99
  - azukiwasher@higanworks.com
17
- executables: []
100
+ executables:
101
+ - solaar
18
102
  extensions: []
19
103
  extra_rdoc_files: []
20
104
  files:
21
- - .document
22
- - .gitignore
105
+ - ".gitignore"
106
+ - ".rspec"
23
107
  - Gemfile
24
- - HISTORY.md
108
+ - Gemfile.lock
25
109
  - LICENSE
110
+ - Procfile
26
111
  - README.md
27
112
  - Rakefile
113
+ - bin/solaar
28
114
  - lib/solaar.rb
29
- - lib/solaar/terms.rb
115
+ - lib/solaar/exception.rb
116
+ - lib/solaar/table.rb
117
+ - lib/solaar/term.rb
118
+ - lib/solaar/version.rb
30
119
  - solaar.gemspec
31
- - test/helper.rb
32
- - test/test_solaar.rb
120
+ - spec/solaar/term_spec.rb
121
+ - spec/spec_helper.rb
33
122
  homepage: http://github.com/azukiwasher/solaar
34
- licenses: []
123
+ licenses:
124
+ - MIT
125
+ metadata: {}
35
126
  post_install_message:
36
127
  rdoc_options: []
37
128
  require_paths:
38
129
  - lib
39
130
  required_ruby_version: !ruby/object:Gem::Requirement
40
- none: false
41
131
  requirements:
42
- - - ! '>='
132
+ - - ">="
43
133
  - !ruby/object:Gem::Version
44
134
  version: '0'
45
135
  required_rubygems_version: !ruby/object:Gem::Requirement
46
- none: false
47
136
  requirements:
48
- - - ! '>='
137
+ - - ">="
49
138
  - !ruby/object:Gem::Version
50
139
  version: '0'
51
140
  requirements: []
52
- rubyforge_project: solaar
53
- rubygems_version: 1.8.15
141
+ rubyforge_project:
142
+ rubygems_version: 2.2.2
54
143
  signing_key:
55
- specification_version: 3
144
+ specification_version: 4
56
145
  summary: Calculates the 24 solar terms until 2099
57
146
  test_files:
58
- - test/helper.rb
59
- - test/test_solaar.rb
147
+ - spec/solaar/term_spec.rb
148
+ - spec/spec_helper.rb
data/.document DELETED
@@ -1,5 +0,0 @@
1
- lib/**/*.rb
2
- bin/*
3
- -
4
- features/**/*.feature
5
- LICENSE.txt
data/HISTORY.md DELETED
@@ -1,13 +0,0 @@
1
- Changes
2
- ================
3
-
4
- 0.1.1 - February 26, 2012
5
- -----
6
-
7
- - Bump the version 0.1.1 adding test file
8
-
9
-
10
- 0.1.0 - February 24, 2012
11
- -----
12
-
13
- - Initial release
@@ -1,77 +0,0 @@
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 given year" if opts[:year].to_i > 2099
41
-
42
- if opts.key?(:month)
43
- s = opts[:month].to_i*2-2
44
- self.solaarterms(opts, [s, s+1])
45
- else
46
- self.solaarterms(opts, nil)
47
- end
48
-
49
- @terms
50
- end
51
-
52
- def solaarterms(opts={}, range=nil)
53
- @terms = []
54
- s, e = range.nil? ? [0,-1] : range
55
-
56
- if opts.key?(:term)
57
- @solaarterms[s..e].each{ |t| @terms << self.formula(opts.merge!(t)) if opts[:term] == t[:ja] }
58
- else
59
- @solaarterms[s..e].each{ |t| @terms << self.formula(opts.merge!(t)) }
60
- end
61
- end
62
-
63
- def formula(opts={})
64
- y = @year = opts[:year]
65
- month = opts.key?(:month) ? opts[:month].to_i : opts[:m]
66
-
67
- y = month <= 2 ? y - 1 : y
68
- day = opts[:day] + opts[:adj] * (y - 1900) - ((y - 1900) / 4)
69
- Hash[date: Time.new(@year, month, day).strftime("%F"), ja: opts[:ja], en: opts[:en]]
70
- end
71
-
72
- def year
73
- @year ||= Time.now.year
74
- end
75
-
76
- end
77
- end
@@ -1,19 +0,0 @@
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
- require 'shoulda'
14
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
15
- $LOAD_PATH.unshift(File.dirname(__FILE__))
16
-
17
- require 'solaar'
18
- class Test::Unit::TestCase
19
- end
@@ -1,60 +0,0 @@
1
- # -*- encoding: UTF-8 -*-
2
- require 'helper'
3
-
4
- class TestSolaar < Test::Unit::TestCase
5
-
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
59
- end
60
- end