shinycolors 0.2.2

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
+ SHA256:
3
+ metadata.gz: 299fbd84f01449083f6664335ded9154653066f0a231c60f6012b74c49e01942
4
+ data.tar.gz: 67c68590735e32368ae28a8723e512ce61cadc30ef899e8e89c1f1d8bb515852
5
+ SHA512:
6
+ metadata.gz: d708f8221c4838d7c9f54e6320c20e6b3f7f73a31e97c6e55f4002164bd5c636a6653fcb90bf04fc6b6b2884c0d4f7b1992e10ddc2bdce0a6a0aa4c3ba2d6ef4
7
+ data.tar.gz: 16467ade697ba26a447e3e3ca984aac3182047338d102f38ffd65315f3e6633848414f457e8eff63bb642dd5c0b010659b756d304896adfb74a99a17438560b5
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'shinycolors/version'
4
+ require 'shinycolors/idol'
5
+ require 'shinycolors/unit'
6
+
7
+ module ShinyColors
8
+ class << self
9
+ Idol.names.each do |name|
10
+ define_method(name) do
11
+ Idol.find(name)
12
+ end
13
+ end
14
+
15
+ Idol.nicknames.each do |nickname, fullname|
16
+ define_method(nickname) do
17
+ Idol.find(fullname)
18
+ end
19
+ end
20
+
21
+ Unit.names.each do |name|
22
+ define_method(name) do
23
+ Unit.find(name)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+ require 'active_support/core_ext/hash'
5
+ require './lib/shinycolors/unit'
6
+
7
+ module ShinyColors
8
+ class Idol
9
+ class NotFoundError < StandardError; end
10
+
11
+ def initialize(name:, cv:, age:, birthplace:, birthday:, nickname_key:, nickname_kana:)
12
+ @name = name
13
+ @cv = cv
14
+ @age = age
15
+ @birthplace = birthplace
16
+ @birthday = birthday
17
+ @nickname_key = nickname_key
18
+ @nickname_kana = nickname_kana
19
+ end
20
+
21
+ attr_reader :name, :cv, :age, :birthplace, :birthday, :nickname_key, :nickname_kana
22
+
23
+ class << self
24
+ def all
25
+ return @all unless @all.nil?
26
+
27
+ @all = YAML.load_file('./data/idol.yml').each_with_object({}) do |(_, values), result|
28
+ result.merge!(values['idols'])
29
+ end.deep_symbolize_keys!
30
+ end
31
+
32
+ def names
33
+ all.keys
34
+ end
35
+
36
+ def nicknames
37
+ all.each_with_object({}) do |(fullname, values), result|
38
+ values[:nickname_key]&.each { |nickname| result.merge!({ nickname => fullname }) }
39
+ end
40
+ end
41
+
42
+ def find(name)
43
+ h = all[name]
44
+ raise(NotFoundError) if h.nil?
45
+
46
+ new(**h)
47
+ end
48
+ end
49
+
50
+ def nickname
51
+ nickname_kana
52
+ end
53
+
54
+ def unit_name
55
+ Unit.all.find do |_, values|
56
+ values[:idols].key?(key_name)
57
+ end.last[:name]
58
+ end
59
+
60
+ alias unit unit_name
61
+
62
+ private
63
+
64
+ def key_name
65
+ Idol.all.find do |_, values|
66
+ name == values[:name]
67
+ end.first
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+
5
+ module ShinyColors
6
+ class Unit
7
+ class NotFoundError < StandardError; end
8
+
9
+ def initialize(name:, name_jp:, color:, idols:)
10
+ @name = name
11
+ @name_jp = name_jp
12
+ @color = color
13
+ @idols = idols
14
+ end
15
+
16
+ attr_reader :name, :name_jp, :color, :idols
17
+
18
+ class << self
19
+ def all
20
+ return @all unless @all.nil?
21
+
22
+ @all = YAML.load_file('./data/idol.yml').deep_symbolize_keys!
23
+ end
24
+
25
+ def names
26
+ all.keys
27
+ end
28
+
29
+ def find(name)
30
+ h = all[name]
31
+ raise(IdolNotFoundError) if h.nil?
32
+
33
+ new(**h)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShinyColors
4
+ VERSION = '0.2.2'
5
+ end
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shinycolors
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.2
5
+ platform: ruby
6
+ authors:
7
+ - iavivai
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-05-20 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: 'shinycolorsは「アイドルマスター シャイニーカラーズ」の情報をRubyで扱えるようにするためのgemです。
14
+
15
+ '
16
+ email:
17
+ - 18yukitaka@gmail.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - lib/shinycolors.rb
23
+ - lib/shinycolors/idol.rb
24
+ - lib/shinycolors/unit.rb
25
+ - lib/shinycolors/version.rb
26
+ homepage: https://github.com/iavivai/shinycolors
27
+ licenses:
28
+ - MIT
29
+ metadata:
30
+ homepage_uri: https://github.com/iavivai/shinycolors
31
+ source_code_uri: https://github.com/iavivai/shinycolors
32
+ post_install_message:
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 2.5.0
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubygems_version: 3.1.2
48
+ signing_key:
49
+ specification_version: 4
50
+ summary: Rubyでシャニマスを扱えるようにするgem
51
+ test_files: []