etoji 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f9221749c7d4b81d689b5374d482a46f50b9c0b362b8e33864871bcadfc9ecf9
4
+ data.tar.gz: f8eeb9b427ec6a1be88811019ec245bf680579a2549e1fe3236928580596f7f6
5
+ SHA512:
6
+ metadata.gz: 4034b814a166c7ec57eb1414d9e01b2f861b1003ca5ca817a6dbb42b29e312115ac2fcf6c3b8a512e74ad625e720e78f86070e4df63c08b2b6cbfda9c38c183b
7
+ data.tar.gz: fa6f6777389c7e2a4dd9b837041ffb13527eaf7d43e4fac9663a8234f00881101f029f8109240e6264e922ca7e05b307cc184da325d27827d6df982a84a2ed56
@@ -0,0 +1,28 @@
1
+ name: test
2
+
3
+ on:
4
+ pull_request:
5
+ types:
6
+ - opened
7
+ - synchronize
8
+ - reopened
9
+ push:
10
+ branches:
11
+ - main
12
+
13
+ jobs:
14
+ build:
15
+ runs-on: ubuntu-latest
16
+ strategy:
17
+ matrix:
18
+ ruby:
19
+ - '3.2.0'
20
+ steps:
21
+ - uses: actions/checkout@v2
22
+ - name: Set up Ruby
23
+ uses: ruby/setup-ruby@v1
24
+ with:
25
+ ruby-version: ${{ matrix.ruby }}
26
+ bundler-cache: true
27
+ - name: Run the default task
28
+ run: bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.ruby-version
2
+ /.bundle/
3
+ /.yardoc
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /Gemfile.lock
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in etoji.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 mitsubosh
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.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # Etoji
2
+
3
+ [![test](https://github.com/MITSUBOSHI/etoji/actions/workflows/test.yml/badge.svg)](https://github.com/MITSUBOSHI/etoji/actions/workflows/test.yml)
4
+
5
+
6
+ Simple 干支(eto) library
7
+
8
+ ## Usage
9
+
10
+ ```ruby
11
+ require 'etoji'
12
+ Etoji.geto(year: 2023)
13
+
14
+ # => #<data Etoji::Jyunishi::Animal
15
+ # number=4,
16
+ # emoji="🐰",
17
+ # character="卯",
18
+ # character_hiragana="う",
19
+ # animal_name_ja="兎",
20
+ # animal_name_ja_hiragana="うさぎ",
21
+ # animal_name_en="rabbit">
22
+ ```
23
+
24
+ ```ruby
25
+ require 'etoji'
26
+ Etoji.geto_full_string(year: 2023)
27
+ # => "癸卯"
28
+ ```
29
+
30
+ ## License
31
+
32
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "etoji"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -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
data/db/jikkan.json ADDED
@@ -0,0 +1,62 @@
1
+ [
2
+ {
3
+ "number": 1,
4
+ "character": "甲",
5
+ "character_hiragana_on": "こう",
6
+ "character_hiragana_kun": "きのえ"
7
+ },
8
+ {
9
+ "number": 2,
10
+ "character": "乙",
11
+ "character_hiragana_on": "おつ",
12
+ "character_hiragana_kun": "きのと"
13
+ },
14
+ {
15
+ "number": 3,
16
+ "character": "丙",
17
+ "character_hiragana_on": "へい",
18
+ "character_hiragana_kun": "ひのえ"
19
+ },
20
+ {
21
+ "number": 4,
22
+ "character": "丁",
23
+ "character_hiragana_on": "てい",
24
+ "character_hiragana_kun": "ひのと"
25
+ },
26
+ {
27
+ "number": 5,
28
+ "character": "戊",
29
+ "character_hiragana_on": "ぼ",
30
+ "character_hiragana_kun": "つちのえ"
31
+ },
32
+ {
33
+ "number": 6,
34
+ "character": "己",
35
+ "character_hiragana_on": "き",
36
+ "character_hiragana_kun": "つちのと"
37
+ },
38
+ {
39
+ "number": 7,
40
+ "character": "庚",
41
+ "character_hiragana_on": "こう",
42
+ "character_hiragana_kun": "かのえ"
43
+ },
44
+ {
45
+ "number": 8,
46
+ "character": "辛",
47
+ "character_hiragana_on": "しん",
48
+ "character_hiragana_kun": "かのと"
49
+ },
50
+ {
51
+ "number": 9,
52
+ "character": "壬",
53
+ "character_hiragana_on": "じん",
54
+ "character_hiragana_kun": "みずのえ"
55
+ },
56
+ {
57
+ "number": 10,
58
+ "character": "癸",
59
+ "character_hiragana_on": "き",
60
+ "character_hiragana_kun": "みずのと"
61
+ }
62
+ ]
data/db/jyunishi.json ADDED
@@ -0,0 +1,134 @@
1
+ [
2
+ {
3
+ "number": 1,
4
+ "emoji": "🐭",
5
+ "character": "子",
6
+ "character_hiragana": "ね",
7
+ "animal_name": {
8
+ "ja": "鼠",
9
+ "ja_hiragana": "ねずみ",
10
+ "en": "mouse"
11
+ }
12
+ },
13
+ {
14
+ "number": 2,
15
+ "emoji": "🐮",
16
+ "character": "丑",
17
+ "character_hiragana": "うし",
18
+ "animal_name": {
19
+ "ja": "牛",
20
+ "ja_hiragana": "うし",
21
+ "en": "cow"
22
+ }
23
+ },
24
+ {
25
+ "number": 3,
26
+ "emoji": "🐯",
27
+ "character": "寅",
28
+ "character_hiragana": "とら",
29
+ "animal_name": {
30
+ "ja": "虎",
31
+ "ja_hiragana": "とら",
32
+ "en": "tiger"
33
+ }
34
+ },
35
+ {
36
+ "number": 4,
37
+ "emoji": "🐰",
38
+ "character": "卯",
39
+ "character_hiragana": "う",
40
+ "animal_name": {
41
+ "ja": "兎",
42
+ "ja_hiragana": "うさぎ",
43
+ "en": "rabbit"
44
+ }
45
+ },
46
+ {
47
+ "number": 5,
48
+ "emoji": "🐲",
49
+ "character": "辰",
50
+ "character_hiragana": "たつ",
51
+ "animal_name": {
52
+ "ja": "龍",
53
+ "ja_hiragana": "りゅう",
54
+ "en": "dragon"
55
+ }
56
+ },
57
+ {
58
+ "number": 6,
59
+ "emoji": "🐍",
60
+ "character": "巳",
61
+ "character_hiragana": "たつ",
62
+ "animal_name": {
63
+ "ja": "蛇",
64
+ "ja_hiragana": "へび",
65
+ "en": "snake"
66
+ }
67
+ },
68
+ {
69
+ "number": 7,
70
+ "emoji": "🐴",
71
+ "character": "午",
72
+ "character_hiragana": "うま",
73
+ "animal_name": {
74
+ "ja": "馬",
75
+ "ja_hiragana": "うま",
76
+ "en": "horse"
77
+ }
78
+ },
79
+ {
80
+ "number": 8,
81
+ "emoji": "🐏",
82
+ "character": "未",
83
+ "character_hiragana": "ひつじ",
84
+ "animal_name": {
85
+ "ja": "羊",
86
+ "ja_hiragana": "ひつじ",
87
+ "en": "sheep"
88
+ }
89
+ },
90
+ {
91
+ "number": 9,
92
+ "emoji": "🐵",
93
+ "character": "申",
94
+ "character_hiragana": "さる",
95
+ "animal_name": {
96
+ "ja": "猿",
97
+ "ja_hiragana": "さる",
98
+ "en": "monkey"
99
+ }
100
+ },
101
+ {
102
+ "number": 10,
103
+ "emoji": "🐔",
104
+ "character": "酉",
105
+ "character_hiragana": "とり",
106
+ "animal_name": {
107
+ "ja": "鶏",
108
+ "ja_hiragana": "にわとり",
109
+ "en": "rooster"
110
+ }
111
+ },
112
+ {
113
+ "number": 11,
114
+ "emoji": "🐶",
115
+ "character": "戌",
116
+ "character_hiragana": "いぬ",
117
+ "animal_name": {
118
+ "ja": "犬",
119
+ "ja_hiragana": "いぬ",
120
+ "en": "dog"
121
+ }
122
+ },
123
+ {
124
+ "number": 12,
125
+ "emoji": "🐗",
126
+ "character": "亥",
127
+ "character_hiragana": "い",
128
+ "animal_name": {
129
+ "ja": "猪",
130
+ "ja_hiragana": "いのしし",
131
+ "en": "boar"
132
+ }
133
+ }
134
+ ]
data/etoji.gemspec ADDED
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/etoji/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "etoji"
7
+ spec.version = Etoji::VERSION
8
+ spec.authors = ["mitsubosh"]
9
+ spec.email = ["yuya.mitsuboshi@gmail.com"]
10
+
11
+ spec.summary = "Simple 干支(eto) library"
12
+ spec.description = "Simple 干支(eto) library"
13
+ spec.homepage = "https://github.com/MITSUBOSHI/etoji"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 3.2.0")
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/MITSUBOSHI/etoji"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ # Uncomment to register a new dependency of your gem
30
+ # spec.add_dependency "example-gem", "~> 1.0"
31
+
32
+ # For more information and examples about making a new gem, checkout our
33
+ # guide at: https://bundler.io/guides/creating_gem.html
34
+ end
@@ -0,0 +1 @@
1
+ 3.2.0
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+ require 'json'
3
+
4
+ module Etoji
5
+ module Jikkan
6
+ class NotFound < StandardError; end
7
+
8
+ SOURCE_FILE_PATH = File.expand_path('../../../db/jikkan.json', __FILE__)
9
+ Kan = ::Data.define(:number, :character, :character_hiragana_on, :character_hiragana_kun)
10
+ MEMBERS = JSON.parse(File.read(SOURCE_FILE_PATH), symbolize_names: true).map { |attributes|
11
+ Kan.new(
12
+ number: attributes[:number],
13
+ character: attributes[:character],
14
+ character_hiragana_on: attributes[:character_hiragana_on],
15
+ character_hiragana_kun: attributes[:character_hiragana_kun],
16
+ )
17
+ }.freeze
18
+
19
+ def self.all
20
+ MEMBERS
21
+ end
22
+
23
+ def self.find_by_number(number)
24
+ @kans_by_number ||= MEMBERS.each_with_object({}) { |kan, result| result[kan.number] = kan }
25
+ @kans_by_number[number] or raise NotFound.new("Number: #{number} is not found")
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+ require 'json'
3
+
4
+ module Etoji
5
+ module Jyunishi
6
+ class NotFound < StandardError; end
7
+
8
+ SOURCE_FILE_PATH = File.expand_path('../../../db/jyunishi.json', __FILE__)
9
+ Animal = ::Data.define(:number, :emoji, :character, :character_hiragana, :animal_name_ja, :animal_name_ja_hiragana, :animal_name_en)
10
+ MEMBERS = JSON.parse(File.read(SOURCE_FILE_PATH), symbolize_names: true).map { |attributes|
11
+ Animal.new(
12
+ number: attributes[:number],
13
+ emoji: attributes[:emoji],
14
+ character: attributes[:character],
15
+ character_hiragana: attributes[:character_hiragana],
16
+ animal_name_ja: attributes.dig(:animal_name, :ja),
17
+ animal_name_ja_hiragana: attributes.dig(:animal_name, :ja_hiragana),
18
+ animal_name_en: attributes.dig(:animal_name, :en)
19
+ )
20
+ }.freeze
21
+
22
+ def self.all
23
+ MEMBERS
24
+ end
25
+
26
+ def self.find_by_number(number)
27
+ @animals_by_number ||= MEMBERS.each_with_object({}) { |animal, result| result[animal.number] = animal }
28
+ @animals_by_number[number] or raise NotFound.new("Number: #{number} is not found")
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Etoji
4
+ VERSION = "0.1.0"
5
+ end
data/lib/etoji.rb ADDED
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "etoji/version"
4
+ require "etoji/jikkan"
5
+ require "etoji/jyunishi"
6
+
7
+ module Etoji
8
+ class Error < StandardError; end
9
+
10
+ def self.geto(year:, with_prev: false, with_next: false)
11
+ year_int = self.convert_year(year)
12
+
13
+ jyunishi_number = ((year_int + 8) % 12 + 1)
14
+ current_animal = ::Etoji::Jyunishi.find_by_number(jyunishi_number)
15
+
16
+ case [with_prev, with_next]
17
+ in [true, true]
18
+ prev_animal = ::Etoji.geto(year: year_int - 1)
19
+ next_animal = ::Etoji.geto(year: year_int + 1)
20
+ [prev_animal, current_animal, next_animal]
21
+ in [true, false]
22
+ prev_animal = ::Etoji.geto(year: year_int - 1)
23
+ [prev_animal, current_animal]
24
+ in [false, true]
25
+ next_animal = ::Etoji.geto(year: year_int + 1)
26
+ [current_animal, next_animal]
27
+ else
28
+ current_animal
29
+ end
30
+ end
31
+
32
+ def self.geto_full_string(year:)
33
+ year_int = self.convert_year(year)
34
+
35
+ jikkan_number = ((year_int + 6) % 10 + 1)
36
+ current_kan = ::Etoji::Jikkan.find_by_number(jikkan_number)
37
+ current_animal = ::Etoji.geto(year: year_int)
38
+
39
+ [current_kan.character, current_animal.character].join
40
+ end
41
+
42
+ def self.convert_year(year)
43
+ year = Integer(year)
44
+ raise 'Not allowed year is given' unless (1..3000).include?(year)
45
+ year
46
+ rescue => e
47
+ raise ::Etoji::Error.new("Invalid year is given, #{e.message}")
48
+ end
49
+ private_class_method :convert_year
50
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: etoji
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - mitsubosh
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-01-04 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Simple 干支(eto) library
14
+ email:
15
+ - yuya.mitsuboshi@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".github/workflows/test.yml"
21
+ - ".gitignore"
22
+ - ".rspec"
23
+ - Gemfile
24
+ - LICENSE.txt
25
+ - README.md
26
+ - Rakefile
27
+ - bin/console
28
+ - bin/setup
29
+ - db/jikkan.json
30
+ - db/jyunishi.json
31
+ - etoji.gemspec
32
+ - lib/etoji.rb
33
+ - lib/etoji/.ruby-version
34
+ - lib/etoji/jikkan.rb
35
+ - lib/etoji/jyunishi.rb
36
+ - lib/etoji/version.rb
37
+ homepage: https://github.com/MITSUBOSHI/etoji
38
+ licenses:
39
+ - MIT
40
+ metadata:
41
+ homepage_uri: https://github.com/MITSUBOSHI/etoji
42
+ source_code_uri: https://github.com/MITSUBOSHI/etoji
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: 3.2.0
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubygems_version: 3.4.1
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: Simple 干支(eto) library
62
+ test_files: []