ehou 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 57aba793e68b5b06e63ab48946d2ec2251991f93
4
+ data.tar.gz: 66dc11280c60cd1ad65d0e2cbca005ff8aabac15
5
+ SHA512:
6
+ metadata.gz: 219b7d30fef7937b755998dcb3bc14800118c67b464411f96b3c14e7902537b26746dda0b1e3f90ea83e3f94a0d3750c8b6a53a0202df2092e9348118e322ab7
7
+ data.tar.gz: 467a39c7a64315bcc258bd67d8f00544b03ee7475874496dea39e4a2a6261f317f168f237d5159b3f326c9f197806fef3023d0fa2dd720a2181f3d34b01cd1b6
@@ -0,0 +1 @@
1
+ service_name: travis-ci
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ script: 'bundle exec rake spec'
3
+ rvm:
4
+ - 1.9.3
5
+ - 2.1.4
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :test do
6
+ gem 'rspec'
7
+ gem 'activesupport'
8
+ gem 'coveralls', :require => false
9
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Koozyt, Inc.
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.
@@ -0,0 +1,57 @@
1
+ # Ehou
2
+
3
+ [![Build Status](https://travis-ci.org/koozyt/ehou.svg?branch=master)](https://travis-ci.org/koozyt/ehou)
4
+ [![Coverage Status](https://coveralls.io/repos/koozyt/ehou/badge.svg?branch=master)](https://coveralls.io/r/koozyt/ehou?branch=master)
5
+ [![Code Climate](https://codeclimate.com/github/koozyt/ehou/badges/gpa.svg)](https://codeclimate.com/github/koozyt/ehou)
6
+
7
+ Patches `Date` and `Time` to add methods and convert to Japanese **Ehou** direction.
8
+
9
+ Ehou is the lucky direction of the year which is determined every year by the [Celestial stems][1].
10
+ It is customary in Japan at Setsubun (celebrated on Feb 3) to eat a special sushi roll in silence facing the "Ehou" direction for good fortune.
11
+
12
+ Have a great Setsubun!
13
+
14
+ For more info on "Ehou", see: [Ehou][2]
15
+
16
+ [1]:http://en.wikipedia.org/wiki/Celestial_stem
17
+ [2]:http://ja.wikipedia.org/wiki/%E6%AD%B3%E5%BE%B3%E7%A5%9E#.E6.81.B5.E6.96.B9
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ require 'ehou'
23
+
24
+ Date.new(2015).ehou # "西南西"
25
+ Date.new(2015).ehou.angle # 255 (0 means north, 90 is east, 180 is south)
26
+ Date.new(2015).ehou.to_en # "West-southwest"
27
+ Date.new(2015).ehou.shorten # "WSW"
28
+ Time.local(2016).ehou # "南南東"
29
+ Time.local(2016).ehou.angle # 165
30
+ Time.local(2016).ehou.to_en # "South-southeast"
31
+ Time.local(2016).ehou.shorten # "SSE"
32
+ ```
33
+
34
+ ## Installation
35
+
36
+ Add this line to your application's Gemfile:
37
+
38
+ ```ruby
39
+ gem 'ehou'
40
+ ```
41
+
42
+ And then execute:
43
+
44
+ $ bundle
45
+
46
+ Or install it yourself as:
47
+
48
+ $ gem install ehou
49
+
50
+ ## Contributing
51
+
52
+ 1. Fork it ( https://github.com/koozyt/ehou/fork )
53
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
54
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
55
+ 4. Make sure all your changes are covered by tests
56
+ 4. Push to the branch (`git push origin my-new-feature`)
57
+ 5. Create a new Pull Request
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ehou/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ehou"
8
+ spec.version = Ehou::VERSION
9
+ spec.authors = ["ikesato"]
10
+ spec.email = ["github@koozyt.com"]
11
+ spec.summary = %q{Japanese Ehou converter}
12
+ spec.description = %q{Patches Date and Time to add methods and convert to Japanese Ehou direction.}
13
+ spec.homepage = "https://github.com/koozyt/ehou"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
@@ -0,0 +1,6 @@
1
+ require 'ehou/version'
2
+ require 'ehou/ehou_extend'
3
+ require 'ehou/ehou_string'
4
+
5
+ module Ehou
6
+ end
@@ -0,0 +1,18 @@
1
+ # coding: utf-8
2
+ require 'date'
3
+
4
+ module Ehou
5
+ module EhouExtend
6
+ def ehou
7
+ return @ehou if @ehou
8
+ @ehou = EhouString.new(self.year)
9
+ end
10
+ end
11
+ end
12
+
13
+ ::Date.class_eval do
14
+ include ::Ehou::EhouExtend
15
+ end
16
+ ::Time.class_eval do
17
+ include ::Ehou::EhouExtend
18
+ end
@@ -0,0 +1,44 @@
1
+ # coding: utf-8
2
+
3
+ module Ehou
4
+ class EhouString < String
5
+ EHOU_ENE = {angle: 75, shorten:"ENE", ja:"東北東", en:"East-northeast"}
6
+ EHOU_SSE = {angle: 165, shorten:"SSE", ja:"南南東", en:"South-southeast"}
7
+ EHOU_WSW = {angle: 255, shorten:"WSW", ja:"西南西", en:"West-southwest"}
8
+ EHOU_NNW = {angle: 345, shorten:"NNW", ja:"北北西", en:"North-northwest"}
9
+ EHOUS = {
10
+ 0 => EHOU_WSW,
11
+ 1 => EHOU_SSE,
12
+ 2 => EHOU_NNW,
13
+ 3 => EHOU_SSE,
14
+ 4 => EHOU_ENE,
15
+ 5 => EHOU_WSW,
16
+ 6 => EHOU_SSE,
17
+ 7 => EHOU_NNW,
18
+ 8 => EHOU_SSE,
19
+ 9 => EHOU_ENE
20
+ }
21
+
22
+ def initialize(year)
23
+ y = year % 10
24
+ @ehou = EHOUS[y]
25
+ super(@ehou[:ja])
26
+ end
27
+
28
+ def angle
29
+ @ehou[:angle]
30
+ end
31
+
32
+ def shorten
33
+ @ehou[:shorten]
34
+ end
35
+
36
+ def to_en
37
+ @ehou[:en]
38
+ end
39
+
40
+ def to_ja
41
+ self
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,3 @@
1
+ module Ehou
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,51 @@
1
+ # coding: utf-8
2
+ require 'spec_helper'
3
+ require 'active_support/time'
4
+
5
+ describe Ehou::EhouExtend do
6
+ describe Date do
7
+ it 'should return ehou string' do
8
+ expect(Date.new(2014).ehou).to eq "東北東"
9
+ expect(Date.new(2015).ehou).to eq "西南西"
10
+ end
11
+
12
+ it 'should return ehou angle' do
13
+ expect(Date.new(2014).ehou.angle).to eq 75
14
+ expect(Date.new(2015).ehou.angle).to eq 255
15
+ end
16
+
17
+ it 'should return same object when calling twice' do
18
+ d = Date.new(2014)
19
+ last = d.ehou
20
+ expect(d.ehou.object_id).to eq last.object_id
21
+ end
22
+ end
23
+
24
+ describe Time do
25
+ it 'should return ehou string' do
26
+ expect(Time.local(2014).ehou).to eq "東北東"
27
+ expect(Time.local(2015).ehou).to eq "西南西"
28
+ end
29
+
30
+ it 'should return ehou angle' do
31
+ expect(Time.local(2014).ehou.angle).to eq 75
32
+ expect(Time.local(2015).ehou.angle).to eq 255
33
+ end
34
+
35
+ it 'should return same object when calling twice' do
36
+ d = Time.local(2014)
37
+ last = d.ehou
38
+ expect(d.ehou.object_id).to eq last.object_id
39
+ end
40
+ end
41
+
42
+ describe ActiveSupport::TimeWithZone do
43
+ it 'should work using ActiveSupport::TimeWithZone' do
44
+ Time.zone = 'Asia/Tokyo'
45
+ expect(Time.zone.local(2014).ehou).to eq "東北東"
46
+ expect(Time.zone.local(2014).ehou.angle).to eq 75
47
+ expect(Time.zone.local(2015).ehou).to eq "西南西"
48
+ expect(Time.zone.local(2015).ehou.angle).to eq 255
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ require 'spec_helper'
3
+ require 'active_support/time'
4
+
5
+ describe Ehou::EhouString do
6
+ def get_ehou(year)
7
+ e = Date.new(year)
8
+ [e.ehou.angle, e.ehou, e.ehou.to_ja, e.ehou.shorten, e.ehou.to_en]
9
+ end
10
+
11
+ it 'should select correct ehous' do
12
+ expect(get_ehou(2010)).to eq [255, "西南西", "西南西", "WSW", "West-southwest"]
13
+ expect(get_ehou(2011)).to eq [165, "南南東", "南南東", "SSE", "South-southeast"]
14
+ expect(get_ehou(2012)).to eq [345, "北北西", "北北西", "NNW", "North-northwest"]
15
+ expect(get_ehou(2013)).to eq [165, "南南東", "南南東", "SSE", "South-southeast"]
16
+ expect(get_ehou(2014)).to eq [ 75, "東北東", "東北東", "ENE", "East-northeast"]
17
+ expect(get_ehou(2015)).to eq [255, "西南西", "西南西", "WSW", "West-southwest"]
18
+ expect(get_ehou(2016)).to eq [165, "南南東", "南南東", "SSE", "South-southeast"]
19
+ expect(get_ehou(2017)).to eq [345, "北北西", "北北西", "NNW", "North-northwest"]
20
+ expect(get_ehou(2018)).to eq [165, "南南東", "南南東", "SSE", "South-southeast"]
21
+ expect(get_ehou(2019)).to eq [ 75, "東北東", "東北東", "ENE", "East-northeast"]
22
+ end
23
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ehou do
4
+ it 'has a version number' do
5
+ expect(Ehou::VERSION).not_to be nil
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
4
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
5
+ require 'ehou'
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ehou
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ikesato
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Patches Date and Time to add methods and convert to Japanese Ehou direction.
42
+ email:
43
+ - github@koozyt.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".coveralls.yml"
49
+ - ".gitignore"
50
+ - ".rspec"
51
+ - ".travis.yml"
52
+ - Gemfile
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - ehou.gemspec
57
+ - lib/ehou.rb
58
+ - lib/ehou/ehou_extend.rb
59
+ - lib/ehou/ehou_string.rb
60
+ - lib/ehou/version.rb
61
+ - spec/ehou/ehou_extend_spec.rb
62
+ - spec/ehou/ehou_string_spec.rb
63
+ - spec/ehou_spec.rb
64
+ - spec/spec_helper.rb
65
+ homepage: https://github.com/koozyt/ehou
66
+ licenses:
67
+ - MIT
68
+ metadata: {}
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 2.4.2
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: Japanese Ehou converter
89
+ test_files:
90
+ - spec/ehou/ehou_extend_spec.rb
91
+ - spec/ehou/ehou_string_spec.rb
92
+ - spec/ehou_spec.rb
93
+ - spec/spec_helper.rb