wayaku 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/lib/wayaku/version.rb +5 -0
  3. data/lib/wayaku.rb +79 -0
  4. metadata +134 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9f8304dbd4f9b5d485e74abfacc6d42750f33eb8b4f1da1687e5012718ef98ea
4
+ data.tar.gz: b8afc19c636f51ee6afcb8c533135d22203cd79ffd6d58301568fdf8da88dfb3
5
+ SHA512:
6
+ metadata.gz: facbb7d0f634040101bf5ba8de5ee478cc9a6f1a10d9144883c04503e1041dea61a99034c0bd3e59378ad9686d17000cc91cc4146c10ffba6f6eae2a6c293bc2
7
+ data.tar.gz: 619237dd6f433cd8c4ba88040937a62e2268f227b77c8f6a7648af0eb8818ef78c8d9621904176ecb4193750512334031d1a44dfef108d76aba6b96660be5a1e
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Wayaku
4
+ VERSION = '0.1.0'
5
+ end
data/lib/wayaku.rb ADDED
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Wayaku
4
+ autoload :VERSION, 'lib/wayaku/version'
5
+
6
+ extend_object ActiveRecord::Base
7
+
8
+ def wayaku(bool: true)
9
+ array = [model_name.human, model_name.singular, parse_attribute(column_names)]
10
+ puts bool ? format(array) : format_simply(array)
11
+ end
12
+
13
+ def wayaku_enum(attr, bool: true)
14
+ unless enumerized_attributes[attr]
15
+ puts "\e[38;5;196m知らない属性\e[0m"
16
+ return
17
+ end
18
+ array = parse_attribute(attr)
19
+ puts bool ? format(array) : format_simply(array)
20
+ end
21
+
22
+ def wayaku_logicals
23
+ array = parse_attribute(column_names)
24
+ array = format_simply(array)
25
+ puts array.each_slice(2).map(&:first)
26
+ end
27
+
28
+ def wayaku_physicals
29
+ array = parse_attribute(column_names)
30
+ array = format_simply(array)
31
+ puts array.each_slice(2).map(&:second)
32
+ end
33
+
34
+ private
35
+
36
+ def parse_attribute(args)
37
+ [*args].inject([]) do |array, arg|
38
+ additions = []
39
+ scope = "activerecord.attributes.#{model_name.singular}"
40
+ word = I18n.backend.send(:lookup, I18n.locale, arg, scope)
41
+
42
+ additions += [word, arg.to_s] unless word.nil?
43
+
44
+ if respond_to?(:enumerize) && enumerized_attributes[arg]
45
+ additions << enumerized_attributes[arg].values.inject([]) { |rst, val| rst + [val.text, val] }
46
+ end
47
+
48
+ array + additions
49
+ end
50
+ end
51
+
52
+ def format_simply(array)
53
+ _add_indent(array).flatten
54
+ end
55
+
56
+ def format(array)
57
+ array = format_simply(array)
58
+ color_switch = _init_color_switch
59
+ array.map { |value| color_switch.call(value) }
60
+ end
61
+
62
+ def _add_indent(array, indent: 0)
63
+ array.map do |value|
64
+ value.is_a?(Array) ? _add_indent(value, indent: indent + 1) : "\s\s" * indent + value
65
+ end
66
+ end
67
+
68
+ def _init_color_switch
69
+ count = 0
70
+ bool = false
71
+ lambda do |word|
72
+ bool = !bool if count.even?
73
+ count += 1
74
+
75
+ color = bool ? 114 : 177
76
+ "\e[38;5;#{color}m#{word}\e[0m"
77
+ end
78
+ end
79
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wayaku
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - soma
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-11-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 7.1.3.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 7.1.3.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: enumerize
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.8'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sqlite3
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.7.3
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.7.3
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.14.2
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.14.2
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.12'
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: 5.12.2
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - "~>"
84
+ - !ruby/object:Gem::Version
85
+ version: '5.12'
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: 5.12.2
89
+ - !ruby/object:Gem::Dependency
90
+ name: rubocop
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '1.68'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '1.68'
103
+ description:
104
+ email:
105
+ executables: []
106
+ extensions: []
107
+ extra_rdoc_files: []
108
+ files:
109
+ - lib/wayaku.rb
110
+ - lib/wayaku/version.rb
111
+ homepage:
112
+ licenses:
113
+ - MIT
114
+ metadata: {}
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '2.7'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubygems_version: 3.3.7
131
+ signing_key:
132
+ specification_version: 4
133
+ summary: モデルの属性を和訳する
134
+ test_files: []