mk_cal_jpl 0.1.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: 362dd3317abe521d2ec999efc27cb3ea69959467
4
+ data.tar.gz: eb88747c2741339efb7e6b8197a4fc65db694d6f
5
+ SHA512:
6
+ metadata.gz: dd086b90a2d554b75230e3e9b7e44bfca9108f974d1e7b10f070d88d0a13f5371979499dc7eeac2f597c49ba452a47765644f38f3bbb7d1d79eb2a59a0215f53
7
+ data.tar.gz: ac53dab8b828a850b5779cbfac6ee77ddc1475672178babc62a701a895f601230486819e807416ca56dc8ac10d5fe18694d99fc6170ef963631c75f0c83e765b
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mk_cal_jpl.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem "guard"
8
+ gem "guard-rspec", "~> 4.7.0"
9
+ end
@@ -0,0 +1,70 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features) \
6
+ # .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
+
8
+ ## Note: if you are using the `directories` clause above and you are not
9
+ ## watching the project directory ('.'), then you will want to move
10
+ ## the Guardfile to a watched dir and symlink it back, e.g.
11
+ #
12
+ # $ mkdir config
13
+ # $ mv Guardfile config/
14
+ # $ ln -s config/Guardfile .
15
+ #
16
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17
+
18
+ # Note: The cmd option is now required due to the increasing number of ways
19
+ # rspec may be run, below are examples of the most common uses.
20
+ # * bundler: 'bundle exec rspec'
21
+ # * bundler binstubs: 'bin/rspec'
22
+ # * spring: 'bin/rspec' (This will use spring if running and you have
23
+ # installed the spring binstubs per the docs)
24
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
25
+ # * 'just' rspec: 'rspec'
26
+
27
+ guard :rspec, cmd: "bundle exec rspec" do
28
+ require "guard/rspec/dsl"
29
+ dsl = Guard::RSpec::Dsl.new(self)
30
+
31
+ # Feel free to open issues for suggestions and improvements
32
+
33
+ # RSpec files
34
+ rspec = dsl.rspec
35
+ watch(rspec.spec_helper) { rspec.spec_dir }
36
+ watch(rspec.spec_support) { rspec.spec_dir }
37
+ watch(rspec.spec_files)
38
+
39
+ # Ruby files
40
+ ruby = dsl.ruby
41
+ dsl.watch_spec_files_for(ruby.lib_files)
42
+
43
+ ## Rails files
44
+ #rails = dsl.rails(view_extensions: %w(erb haml slim))
45
+ #dsl.watch_spec_files_for(rails.app_files)
46
+ #dsl.watch_spec_files_for(rails.views)
47
+
48
+ #watch(rails.controllers) do |m|
49
+ # [
50
+ # rspec.spec.call("routing/#{m[1]}_routing"),
51
+ # rspec.spec.call("controllers/#{m[1]}_controller"),
52
+ # rspec.spec.call("acceptance/#{m[1]}")
53
+ # ]
54
+ #end
55
+
56
+ ## Rails config changes
57
+ #watch(rails.spec_helper) { rspec.spec_dir }
58
+ #watch(rails.routes) { "#{rspec.spec_dir}/routing" }
59
+ #watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
60
+
61
+ ## Capybara features specs
62
+ #watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
63
+ #watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
64
+
65
+ ## Turnip features and steps
66
+ #watch(%r{^spec/acceptance/(.+)\.feature$})
67
+ #watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
68
+ # Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
69
+ #end
70
+ end
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Masaru Koizumi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,107 @@
1
+ # MkCalendar
2
+
3
+ ## Introduction
4
+
5
+ This is the gem library which calculates calendar datas, including old-calendar.(by JPL DE430)
6
+
7
+ ### Computable items
8
+
9
+ julian day(utc), julian day(jst), holiday, sekki_24, zassetsu,
10
+ yobi, kanshi, sekku, lambda(sun), alpha(moon), moonage,
11
+ old-calendar(year, month, day, leap flag), rokuyo
12
+
13
+ ### Original Text
14
+
15
+ [旧暦計算サンプルプログラム](http://www.vector.co.jp/soft/dos/personal/se016093.html)
16
+ Copyright (C) 1993,1994 by H.Takano
17
+
18
+ ### Remark
19
+
20
+ However, the above program includes some problems for calculating the future
21
+ old-calendar datas. So, I have done some adjustments.(by JPL DE430 etc.)
22
+
23
+ ## Preparation
24
+
25
+ This library needs a JPL's DE430 binary file.
26
+
27
+ Download linux_p1550p2650.430 from [ftp://ssd.jpl.nasa.gov/pub/eph/planets/Linux/de430/](ftp://ssd.jpl.nasa.gov/pub/eph/planets/Linux/de430/), and place at a suitable directory.
28
+
29
+ If neccessary, rename the binary file.
30
+
31
+ ## Installation
32
+
33
+ Add this line to your application's Gemfile:
34
+
35
+ ```ruby
36
+ gem 'mk_cal_jpl'
37
+ ```
38
+
39
+ And then execute:
40
+
41
+ $ bundle
42
+
43
+ Or install it yourself as:
44
+
45
+ $ gem install mk_cal_jpl
46
+
47
+ ## Usage
48
+
49
+ ### Instantiation
50
+
51
+ require 'mk_cal_jpl'
52
+
53
+ o = MkCalJpl.new("/path/to/<JPL DE430 binary>")
54
+
55
+ # Otherwise
56
+ o = MkCalJpl.new("/path/to/<JPL DE430 binary>", "20160916")
57
+
58
+ * Second argument should be JST(Format: `%Y%m%d`).
59
+ * If you don't set a second argument, this class considers the system time to have been set as a second argument(JST).
60
+
61
+ ### Calculation
62
+
63
+ year = o.year
64
+ month = o.month
65
+ day = o.day
66
+ jd = o.jd
67
+ jd_jst = o.jd_jst
68
+ holiday = o.holiday
69
+ sekki_24 = o.sekki_24
70
+ zassetsu = o.zassetsu
71
+ yobi = o.yobi
72
+ kanshi = o.kanshi
73
+ sekku = o.sekku
74
+ lambda = o.lambda
75
+ alpha = o.alpha
76
+ moonage = o.moonage
77
+ oc = o.oc
78
+ str = sprintf("%04d-%02d-%02d", year, month, day)
79
+ str << " #{yobi}曜日"
80
+ str << " #{holiday}" unless holiday == ""
81
+ str << " #{jd}UTC(#{jd_jst}JST) #{kanshi} "
82
+ str << sprintf("%04d-%02d-%02d", oc[0], oc[2], oc[3])
83
+ str << "(閏)" if oc[1] == 1
84
+ str << " #{oc[4]}"
85
+ str << " #{sekki_24}" unless sekki_24 == ""
86
+ str << " #{zassetsu}" unless zassetsu == ""
87
+ str << " #{sekku}" unless sekku == ""
88
+ str << " #{lambda} #{alpha} #{moonage}"
89
+ puts str
90
+
91
+ * It takes time for result output, because this library calculates correctly each time on loop processing.
92
+
93
+ ## Development
94
+
95
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec mk_cal_jpl` to use the gem in this directory, ignoring other installed copies of this gem.
96
+
97
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
98
+
99
+ ## Contributing
100
+
101
+ Bug reports and pull requests are welcome on GitHub at https://github.com/komasaru/mk_cal_jpl.
102
+
103
+
104
+ ## License
105
+
106
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
107
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "mk_cal_jpl"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "mk_cal_jpl"
4
+
5
+ o = MkCalJpl.new(*ARGV) # JPL binary file's path, JST(YYYYMMDD)
6
+ exit unless o
7
+
8
+ year = o.year
9
+ month = o.month
10
+ day = o.day
11
+ jd = o.jd
12
+ jd_jst = o.jd_jst
13
+ holiday = o.holiday
14
+ sekki_24 = o.sekki_24
15
+ zassetsu = o.zassetsu
16
+ yobi = o.yobi
17
+ kanshi = o.kanshi
18
+ sekku = o.sekku
19
+ lambda = o.lambda
20
+ alpha = o.alpha
21
+ moonage = o.moonage
22
+ oc = o.oc
23
+ str = sprintf("%04d-%02d-%02d", year, month, day)
24
+ str << " #{yobi}曜日"
25
+ str << " #{holiday}" unless holiday == ""
26
+ str << " #{jd}UTC(#{jd_jst}JST) #{kanshi} "
27
+ str << sprintf("%04d-%02d-%02d", oc[0], oc[2], oc[3])
28
+ str << "(閏)" if oc[1] == 1
29
+ str << " #{oc[4]}"
30
+ str << " #{sekki_24}" unless sekki_24 == ""
31
+ str << " #{zassetsu}" unless zassetsu == ""
32
+ str << " #{sekku}" unless sekku == ""
33
+ str << " #{lambda} #{alpha} #{moonage}"
34
+ puts str
@@ -0,0 +1,14 @@
1
+ require "mk_apos"
2
+ require "mk_coord"
3
+ require "mk_cal_jpl/version"
4
+ require "mk_cal_jpl/argument"
5
+ require "mk_cal_jpl/calendar"
6
+ require "mk_cal_jpl/compute"
7
+ require "mk_cal_jpl/const"
8
+
9
+ module MkCalJpl
10
+ def self.new(*args)
11
+ bin_path, jst = MkCalJpl::Argument.new(*args).get_args
12
+ return MkCalJpl::Calendar.new(bin_path, jst)
13
+ end
14
+ end
@@ -0,0 +1,44 @@
1
+ require 'date'
2
+
3
+ module MkCalJpl
4
+ class Argument
5
+ def initialize(*args)
6
+ @args = *args
7
+ end
8
+
9
+ #=========================================================================
10
+ # 引数取得
11
+ #
12
+ # @return: [BIN_PATH, JST]
13
+ #=========================================================================
14
+ def get_args
15
+ bin_path = get_binpath
16
+ jst = get_jst
17
+ check_bin_path(bin_path)
18
+ return [bin_path, jst]
19
+ rescue => e
20
+ raise
21
+ end
22
+
23
+ def get_binpath
24
+ raise Const::USAGE unless bin_path = @args.shift
25
+ return bin_path
26
+ end
27
+
28
+ def get_jst
29
+ jst = @args.shift
30
+ unless jst
31
+ now = Time.now
32
+ return [now.year, now.month, now.day]
33
+ end
34
+ raise Const::MSG_ERR_2 unless jst =~ /^\d{8}$/
35
+ year, month, day = jst[ 0, 4].to_i, jst[ 4, 2].to_i, jst[ 6, 2].to_i
36
+ raise Const::MSG_ERR_3 unless Date.valid_date?(year, month, day)
37
+ return [year, month, day]
38
+ end
39
+
40
+ def check_bin_path(bin_path)
41
+ raise Const::MSG_ERR_1 unless File.exist?(bin_path)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,87 @@
1
+ require 'mk_cal_jpl/compute'
2
+
3
+ module MkCalJpl
4
+ class Calendar
5
+ attr_reader :year, :month, :day, :jd, :jd_jst
6
+
7
+ include MkCalJpl::Compute
8
+
9
+ def initialize(bin_path, jst)
10
+ @bin_path = bin_path
11
+ @year, @month, @day = jst
12
+ @jd = gc2jd(@year, @month, @day)
13
+ @jd_jst = @jd + Const::JST_D
14
+ end
15
+
16
+ #=========================================================================
17
+ # 休日
18
+ #=========================================================================
19
+ def holiday
20
+ return compute_holiday(@year, @month, @day)
21
+ end
22
+
23
+ #=========================================================================
24
+ # 二十四節気
25
+ #=========================================================================
26
+ def sekki_24
27
+ return compute_sekki_24(@jd_jst)
28
+ end
29
+
30
+ #=========================================================================
31
+ # 雑節
32
+ #=========================================================================
33
+ def zassetsu
34
+ return compute_zassetsu(@jd_jst)
35
+ end
36
+
37
+ #=========================================================================
38
+ # 曜日
39
+ #=========================================================================
40
+ def yobi
41
+ return compute_yobi(@jd_jst)
42
+ end
43
+
44
+ #=========================================================================
45
+ # 干支
46
+ #=========================================================================
47
+ def kanshi
48
+ return compute_kanshi(@jd_jst)
49
+ end
50
+
51
+ #=========================================================================
52
+ # 節句
53
+ #=========================================================================
54
+ def sekku
55
+ return compute_sekku(@month, @day)
56
+ end
57
+
58
+ #=========================================================================
59
+ # 視黄経(太陽)
60
+ #=========================================================================
61
+ def lambda
62
+ return compute_lambda(@jd_jst)
63
+ end
64
+
65
+ #=========================================================================
66
+ # 視黄経(月)
67
+ #=========================================================================
68
+ def alpha
69
+ return compute_alpha(@jd_jst)
70
+ end
71
+
72
+ #=========================================================================
73
+ # 月齢(正午)
74
+ #=========================================================================
75
+ def moonage
76
+ return compute_moonage(@jd_jst)
77
+ end
78
+
79
+ #=========================================================================
80
+ # 旧暦
81
+ #=========================================================================
82
+ def oc
83
+ return compute_oc(@jd_jst)
84
+ end
85
+ end
86
+ end
87
+