eto 1.0.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: 84a788ac4632d04952f42217b048db94d2a73f89
4
+ data.tar.gz: 6bb17aa13c75ea681fd983e51d280b664c431efb
5
+ SHA512:
6
+ metadata.gz: dc4f615d218039bfa561b3b2b751c224e03c77a7fd43520e757848c06835d0255d90938c08452af2eceded98f8f46b6405df0e966e56c246e46786af4d1c8bd8
7
+ data.tar.gz: c4179d3884d1730e6c67805b59b8260ac6e8f907d475899fa4b3e90e493e393c771f9418c6909708fa48766abbe0063a35d6d7884f808efdfe6d9c5b8aa823cc
@@ -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,2 @@
1
+ --color
2
+ --format progress
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ before_install:
3
+ - gem update --system 2.1.11
4
+ - gem --version
5
+ rvm:
6
+ - 2.0.0
7
+ - 2.1.0
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+ gem 'rspec', '~> 2.14.1'
5
+ gem 'thor', '~> 0.18.1'
6
+ gem 'simplecov', '~> 0.8.2'
7
+
8
+ group :test do
9
+ gem 'coveralls', require: false
10
+ gem 'timecop'
11
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 tbpgr
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,108 @@
1
+ # Eto
2
+
3
+ Get Eto (Japanese Zodiac) name or emoji.
4
+
5
+ [![Build Status](https://travis-ci.org/tbpgr/eto.png?branch=master)](https://travis-ci.org/tbpgr/eto)
6
+ [![Coverage Status](https://coveralls.io/repos/tbpgr/eto/badge.png)](https://coveralls.io/r/tbpgr/eto)
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ~~~bash
13
+ gem 'eto'
14
+ ~~~
15
+
16
+ And then execute:
17
+
18
+ ~~~
19
+ $ bundle
20
+ ~~~
21
+
22
+ Or install it yourself as:
23
+
24
+ ~~~bash
25
+ $ gem install ruboty-articlegen
26
+ ~~~
27
+
28
+ ### Commands (Command Line)
29
+ |name|args|memo|
30
+ |:--|:--|:--|
31
+ |names|--|全ての干支を配列で返却|
32
+ |name|year|year の干支名を取得|
33
+ |emoji|year|year に対応する干支の emoji を取得|
34
+
35
+ ## Usage ( Command Line Interface)
36
+ ### names
37
+ ~~~bash
38
+ $ eto names
39
+ 子丑寅卯辰巳午未申酉戌亥
40
+ ~~~
41
+
42
+ ### name year
43
+ ~~~bash
44
+ $ eto name 1977
45
+
46
+ $ eto name 1977
47
+
48
+ ~~~
49
+
50
+ ### emoji year
51
+ ~~~bash
52
+ $ eto emoji 1977
53
+ :snake:
54
+ $ eto emoji 1977
55
+ :horse:
56
+ ~~~
57
+
58
+ ## Usage ( require gem )
59
+
60
+ ### Eto.names
61
+ ~~~ruby
62
+ require 'eto'
63
+ Eto.names #=> ['子', '丑', '寅', '卯', '辰', '巳', '午', '未', '申', '酉', '戌', '亥']
64
+ ~~~
65
+
66
+ ### Eto.eto_hash
67
+ ~~~ruby
68
+ require 'eto'
69
+ Eto.eto_hash
70
+ __END__
71
+ output
72
+ {
73
+ '子' => ':mouse:',
74
+ '丑' => ':cow:',
75
+ '寅' => ':tiger:',
76
+ '卯' => ':rabbit:',
77
+ '辰' => ':dragon:',
78
+ '巳' => ':snake:',
79
+ '午' => ':horse:',
80
+ '未' => ':sheep:',
81
+ '申' => ':monkey:',
82
+ '酉' => ':chicken:',
83
+ '戌' => ':dog:',
84
+ '亥' => ':boar:'
85
+ }
86
+ ~~~
87
+
88
+ ### Eto.name(year)
89
+ ~~~ruby
90
+ require 'eto'
91
+ Eto.name(1977) #=> '巳'
92
+ Eto.name(1978) #=> '午'
93
+ ~~~
94
+
95
+ ### Eto.emoji(year)
96
+ ~~~ruby
97
+ require 'eto'
98
+ Eto.emoji(1977) #=> ':snake:'
99
+ Eto.emoji(1978) #=> ':horse:'
100
+ ~~~
101
+
102
+ ## Contributing
103
+
104
+ 1. Fork it ( https://github.com/tbpgr/eto/fork )
105
+ 1. Create your feature branch (git checkout -b my-new-feature)
106
+ 1. Commit your changes (git commit -am 'Add some feature')
107
+ 1. Push to the branch (git push origin my-new-feature)
108
+ 1. Create a new Pull Reques
@@ -0,0 +1,8 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core'
3
+ require 'rspec/core/rake_task'
4
+ task default: [:spec]
5
+
6
+ RSpec::Core::RakeTask.new(:spec) do |spec|
7
+ spec.pattern = 'spec/**/*_spec.rb'
8
+ end
data/bin/eto ADDED
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require 'eto'
5
+ require 'eto/version'
6
+ require 'thor'
7
+
8
+ # rubocop: disable MethodLength
9
+ module Eto
10
+ # = Eto CLI
11
+ class CLI < Thor
12
+ class_option :help, type: :boolean, aliases: '-h', desc: 'help message.'
13
+ class_option :version, type: :boolean, desc: 'version'
14
+ class_option :debug, type: :boolean, aliases: '-d', desc: 'debug mode'
15
+
16
+ desc 'names', 'get eto names'
17
+ def names
18
+ setting_debug_mode
19
+ puts Eto.names.join
20
+ rescue => e
21
+ output_error_if_debug_mode(e)
22
+ exit(false)
23
+ end
24
+
25
+ desc 'name', 'get eto name from year'
26
+ def name(year = 1970)
27
+ setting_debug_mode
28
+ puts Eto.name(year)
29
+ rescue => e
30
+ output_error_if_debug_mode(e)
31
+ exit(false)
32
+ end
33
+
34
+ desc 'emoji', 'get eto emoji from year'
35
+ def emoji(year = 1970)
36
+ setting_debug_mode
37
+ puts Eto.emoji(year)
38
+ rescue => e
39
+ output_error_if_debug_mode(e)
40
+ exit(false)
41
+ end
42
+
43
+ desc 'version', 'version'
44
+ def version
45
+ p Eto::VERSION
46
+ end
47
+
48
+ private
49
+
50
+ def setting_debug_mode
51
+ $DEBUG = options[:debug]
52
+ end
53
+
54
+ def output_error_if_debug_mode(e)
55
+ return unless options[:debug]
56
+ STDERR.puts(e.backtrace)
57
+ end
58
+ end
59
+ end
60
+
61
+ Eto::CLI.start(ARGV)
62
+ # rubocop: enable MethodLength
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'eto/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'eto'
8
+ spec.version = Eto::VERSION
9
+ spec.authors = ['tbpgr']
10
+ spec.email = ['tbpgr@tbpgr.jp']
11
+ spec.summary = 'Get Eto (Japanese Zodiac) name or emoji.'
12
+ spec.description = 'Get Eto (Japanese Zodiac) name or emoji.'
13
+ spec.homepage = 'https://github.com/tbpgr/eto'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(/^(test|spec|features)\//)
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_runtime_dependency 'thor'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.6'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ end
@@ -0,0 +1,52 @@
1
+ # encoding: utf-8
2
+
3
+ # Eto
4
+ module Eto
5
+ module_function
6
+
7
+ # Eto Names
8
+ NAMES = %w(子 丑 寅 卯 辰 巳 午 未 申 酉 戌 亥).freeze
9
+ # Eto Hash ( EtoName => EtoEmoji )
10
+ HASH = {
11
+ '子' => ':mouse:',
12
+ '丑' => ':cow:',
13
+ '寅' => ':tiger:',
14
+ '卯' => ':rabbit:',
15
+ '辰' => ':dragon:',
16
+ '巳' => ':snake:',
17
+ '午' => ':horse:',
18
+ '未' => ':sheep:',
19
+ '申' => ':monkey:',
20
+ '酉' => ':chicken:',
21
+ '戌' => ':dog:',
22
+ '亥' => ':boar:'
23
+ }.freeze
24
+
25
+ # get eto names
26
+ def names
27
+ NAMES
28
+ end
29
+
30
+ # get eto eto_hash
31
+ def eto_hash
32
+ HASH
33
+ end
34
+
35
+ # get eto name from year
36
+ def name(year)
37
+ int_year = validate_year(year)
38
+ NAMES[(int_year + 8) % 12]
39
+ end
40
+
41
+ # get eto emoji from year
42
+ def emoji(year)
43
+ int_year = validate_year(year)
44
+ HASH[name(int_year)]
45
+ end
46
+
47
+ private
48
+
49
+ def self.validate_year(year)
50
+ Integer(year)
51
+ end
52
+ end
@@ -0,0 +1,4 @@
1
+ # Eto
2
+ module Eto
3
+ VERSION = '1.0.0'
4
+ end
@@ -0,0 +1,187 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'eto'
4
+
5
+ describe Eto do
6
+ context :names do
7
+ cases = [
8
+ {
9
+ case_no: 1,
10
+ case_title: 'eto names',
11
+ expected: Eto::NAMES
12
+ }
13
+ ]
14
+
15
+ cases.each do |c|
16
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
17
+ begin
18
+ case_before c
19
+
20
+ # -- given --
21
+ # nothing
22
+
23
+ # -- when --
24
+ actual = Eto.names
25
+
26
+ # -- then --
27
+ expect(actual).to eq(c[:expected])
28
+ ensure
29
+ case_after c
30
+ end
31
+ end
32
+
33
+ def case_before(_c)
34
+ # implement each case before
35
+ end
36
+
37
+ def case_after(_c)
38
+ # implement each case after
39
+ end
40
+ end
41
+ end
42
+
43
+ context :eto_hash do
44
+ cases = [
45
+ {
46
+ case_no: 1,
47
+ case_title: 'eto hash',
48
+ expected: Eto::HASH
49
+ }
50
+ ]
51
+
52
+ cases.each do |c|
53
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
54
+ begin
55
+ case_before c
56
+
57
+ # -- given --
58
+ # nothing
59
+
60
+ # -- when --
61
+ actual = Eto.eto_hash
62
+
63
+ # -- then --
64
+ expect(actual).to eq(c[:expected])
65
+ ensure
66
+ case_after c
67
+ end
68
+ end
69
+
70
+ def case_before(_c)
71
+ # implement each case before
72
+ end
73
+
74
+ def case_after(_c)
75
+ # implement each case after
76
+ end
77
+ end
78
+ end
79
+
80
+ context :name do
81
+ cases = [
82
+ {
83
+ case_no: 1,
84
+ case_title: 'eto name from year',
85
+ year: 1977,
86
+ expected: '巳'
87
+ },
88
+ {
89
+ case_no: 2,
90
+ case_title: 'eto name from year',
91
+ year: 1978,
92
+ expected: '午'
93
+ },
94
+ {
95
+ case_no: 3,
96
+ case_title: 'not integer year',
97
+ year: 'abc',
98
+ expect_error: true
99
+ }
100
+ ]
101
+
102
+ cases.each do |c|
103
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
104
+ begin
105
+ case_before c
106
+
107
+ # -- given --
108
+ # nothing
109
+
110
+ # -- when --
111
+ if c[:expect_error]
112
+ expect { Eto.name(c[:year]) }.to raise_error(ArgumentError)
113
+ next
114
+ end
115
+ actual = Eto.name(c[:year])
116
+
117
+ # -- then --
118
+ expect(actual).to eq(c[:expected])
119
+ ensure
120
+ case_after c
121
+ end
122
+ end
123
+
124
+ def case_before(_c)
125
+ # implement each case before
126
+ end
127
+
128
+ def case_after(_c)
129
+ # implement each case after
130
+ end
131
+ end
132
+ end
133
+
134
+ context :emoji do
135
+ cases = [
136
+ {
137
+ case_no: 1,
138
+ case_title: 'eto emoji from year',
139
+ year: 1977,
140
+ expected: ':snake:'
141
+ },
142
+ {
143
+ case_no: 2,
144
+ case_title: 'eto emoji from year',
145
+ year: 1978,
146
+ expected: ':horse:'
147
+ },
148
+ {
149
+ case_no: 3,
150
+ case_title: 'not integer year',
151
+ year: 'abc',
152
+ expect_error: true
153
+ }
154
+ ]
155
+
156
+ cases.each do |c|
157
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
158
+ begin
159
+ case_before c
160
+
161
+ # -- given --
162
+ # nothing
163
+
164
+ # -- when --
165
+ if c[:expect_error]
166
+ expect { Eto.emoji(c[:year]) }.to raise_error(ArgumentError)
167
+ next
168
+ end
169
+ actual = Eto.emoji(c[:year])
170
+
171
+ # -- then --
172
+ expect(actual).to eq(c[:expected])
173
+ ensure
174
+ case_after c
175
+ end
176
+ end
177
+
178
+ def case_before(_c)
179
+ # implement each case before
180
+ end
181
+
182
+ def case_after(_c)
183
+ # implement each case after
184
+ end
185
+ end
186
+ end
187
+ end
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+ require 'simplecov'
3
+ require 'coveralls'
4
+ Coveralls.wear!
5
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
6
+ SimpleCov::Formatter::HTMLFormatter,
7
+ Coveralls::SimpleCov::Formatter
8
+ ]
9
+ SimpleCov.start do
10
+ add_filter '/spec/'
11
+ end
12
+ RSpec.configure do |config|
13
+ config.treat_symbols_as_metadata_keys_with_true_values = true
14
+ config.run_all_when_everything_filtered = true
15
+ config.filter_run :focus
16
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eto
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - tbpgr
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
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: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: Get Eto (Japanese Zodiac) name or emoji.
56
+ email:
57
+ - tbpgr@tbpgr.jp
58
+ executables:
59
+ - eto
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .coveralls.yml
64
+ - .gitignore
65
+ - .rspec
66
+ - .travis.yml
67
+ - Gemfile
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - bin/eto
72
+ - eto.gemspec
73
+ - lib/eto.rb
74
+ - lib/eto/version.rb
75
+ - spec/eto_spec.rb
76
+ - spec/spec_helper.rb
77
+ homepage: https://github.com/tbpgr/eto
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.3.0
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Get Eto (Japanese Zodiac) name or emoji.
101
+ test_files:
102
+ - spec/eto_spec.rb
103
+ - spec/spec_helper.rb