buncho 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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +47 -0
- data/Rakefile +11 -0
- data/bin/buncho +3 -0
- data/data/.keep +0 -0
- data/data/weight/.keep +0 -0
- data/lib/buncho/base_logger.rb +15 -0
- data/lib/buncho/cli.rb +38 -0
- data/lib/buncho/name_logger.rb +34 -0
- data/lib/buncho/name_resolver.rb +36 -0
- data/lib/buncho/version.rb +5 -0
- data/lib/buncho/weight_logger.rb +33 -0
- data/lib/buncho.rb +11 -0
- data/sig/buncho.rbs +4 -0
- metadata +57 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cc6c2ced0cbe56452a4a91fe06edc75ca0b55667b5d42f5b99190e3ec365e35f
|
4
|
+
data.tar.gz: c1265ae82ae14afac1b61d9b5e24e9ae60f15436308a19e477b6d80937e5768d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 14dcd89ca21ef047701b25643696f863e85da23d5a2f735e5b3c533b750ee689f967247687f8418080bf98942e4f4cc744a6cfae0420620891267ada8cdb6794
|
7
|
+
data.tar.gz: 7c368356e0346cfe2d3098d7ee628745b781abf8f6306ff0676f339104ffe97a92f66666fc3d731573ac0003c7992f48236f076a8f58e7623fbac7cff5b1c92d
|
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2025 TODO: Write your name
|
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,47 @@
|
|
1
|
+
# Buncho
|
2
|
+
|
3
|
+
<img src="https://github.com/user-attachments/assets/5f82f06c-976c-4007-a4f9-35b2ffd38e43" alt="Buncho" title="Buncho" width="300">
|
4
|
+
|
5
|
+
This is a Ruby gem for managing the body weight of Buncho.
|
6
|
+
|
7
|
+
# Installation
|
8
|
+
|
9
|
+
```
|
10
|
+
% gem install buncho
|
11
|
+
```
|
12
|
+
|
13
|
+
# Usage
|
14
|
+
|
15
|
+
To register a buncho's name, use the `-n` option.
|
16
|
+
|
17
|
+
```
|
18
|
+
% buncho -n yuki
|
19
|
+
```
|
20
|
+
|
21
|
+
If you specify only -n, it will just register the name without recording weight.
|
22
|
+
You can also combine -n and -w to register both name and weight at once:
|
23
|
+
|
24
|
+
```
|
25
|
+
% buncho -n yuki -w 25
|
26
|
+
```
|
27
|
+
|
28
|
+
You can record the weight using only the -w option.
|
29
|
+
|
30
|
+
```
|
31
|
+
% buncho -w 25
|
32
|
+
```
|
33
|
+
|
34
|
+
You can also register multiple birds.
|
35
|
+
If you try to record a weight without specifying a name, a list of choices will be displayed.
|
36
|
+
|
37
|
+
Example output:
|
38
|
+
|
39
|
+
```
|
40
|
+
% buncho -n yuki
|
41
|
+
% buncho -n sora
|
42
|
+
% buncho -w 26
|
43
|
+
|
44
|
+
Which buncho's data do you want to use? Enter the number.
|
45
|
+
1 sora
|
46
|
+
2 yuki
|
47
|
+
```
|
data/Rakefile
ADDED
data/bin/buncho
ADDED
data/data/.keep
ADDED
File without changes
|
data/data/weight/.keep
ADDED
File without changes
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Buncho
|
2
|
+
class BaseLogger
|
3
|
+
attr_reader :path
|
4
|
+
|
5
|
+
def initialize(path)
|
6
|
+
@path = File.expand_path(path, __FILE__)
|
7
|
+
@io = File.open(path, "a+")
|
8
|
+
end
|
9
|
+
|
10
|
+
def read_lines
|
11
|
+
@io.rewind
|
12
|
+
File.exist?(@path) ? @io.read.split("\n") : []
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/buncho/cli.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "optparse"
|
4
|
+
|
5
|
+
module Buncho
|
6
|
+
class CLI
|
7
|
+
class << self
|
8
|
+
def run(argv)
|
9
|
+
options = {}
|
10
|
+
logger = NameLogger.new
|
11
|
+
|
12
|
+
OptionParser.new do |opts|
|
13
|
+
opts.on("-n NAME", "--name", "Buncho's name (Example: buncho -n Sora)") { |v| options[:name] = v }
|
14
|
+
opts.on("-w WEIGHT", "--wieght", "Buncho's Weight (Example: buncho -w 25)") { |v| options[:weight] = v }
|
15
|
+
opts.on("-l", "--weight-list", "Show list of registered buncho weights") { |v| options[:weight_list] = v }
|
16
|
+
opts.on("-h", "--help", "Show this help message") do
|
17
|
+
puts opts
|
18
|
+
exit
|
19
|
+
end
|
20
|
+
end.parse!
|
21
|
+
|
22
|
+
weight = options[:weight]
|
23
|
+
resolver = NameResolver.new(logger)
|
24
|
+
name = resolver.resolve_name(options[:name])
|
25
|
+
weight_logger = WeightLogger.new(name)
|
26
|
+
|
27
|
+
unless weight.nil?
|
28
|
+
weight_logger.add(weight)
|
29
|
+
puts "#{name}'s weight is #{weight}g."
|
30
|
+
end
|
31
|
+
|
32
|
+
if options[:weight_list]
|
33
|
+
weight_logger.show
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Buncho
|
2
|
+
class NameLogger < BaseLogger
|
3
|
+
DATA_FILE = File.expand_path("../../../data/names.txt", __FILE__)
|
4
|
+
|
5
|
+
attr_reader :names
|
6
|
+
|
7
|
+
def initialize(file_path = DATA_FILE)
|
8
|
+
super(DATA_FILE)
|
9
|
+
@names = read_lines.each_with_index.to_h { |val, i| [i + 1, val.chomp] }
|
10
|
+
end
|
11
|
+
|
12
|
+
def add(name)
|
13
|
+
return if name_exists?(name)
|
14
|
+
|
15
|
+
@io.write("#{name}\n")
|
16
|
+
index = @names.keys.max.to_i + 1
|
17
|
+
@names[index] = name
|
18
|
+
name
|
19
|
+
end
|
20
|
+
|
21
|
+
def show
|
22
|
+
puts "Buncho's List:"
|
23
|
+
puts @names
|
24
|
+
end
|
25
|
+
|
26
|
+
def name_exists?(name)
|
27
|
+
@names.value?(name)
|
28
|
+
end
|
29
|
+
|
30
|
+
def formatted_rows
|
31
|
+
@names.each { |k, v| "#{k}. #{v}" }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Buncho
|
2
|
+
class NameResolver
|
3
|
+
def initialize(logger)
|
4
|
+
@logger = logger
|
5
|
+
end
|
6
|
+
|
7
|
+
def resolve_name(name)
|
8
|
+
name&.chomp!
|
9
|
+
names = @logger.names
|
10
|
+
|
11
|
+
if names.value?(name)
|
12
|
+
return name
|
13
|
+
end
|
14
|
+
|
15
|
+
if name && !names.value?(name)
|
16
|
+
@logger.add(name)
|
17
|
+
return name
|
18
|
+
end
|
19
|
+
|
20
|
+
if names.nil? || names.empty?
|
21
|
+
puts "Error: Please register your buncho's name."
|
22
|
+
puts "Example: buncho -n NAME"
|
23
|
+
exit 1
|
24
|
+
end
|
25
|
+
|
26
|
+
if names.size == 1
|
27
|
+
return names.values.first
|
28
|
+
end
|
29
|
+
|
30
|
+
puts "Which buncho's data do you want to use? Enter the number."
|
31
|
+
names.each { |k, v| puts "#{k} #{v}" }
|
32
|
+
input = STDIN.gets.chomp
|
33
|
+
names[input.to_i]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
module Buncho
|
4
|
+
class WeightLogger < BaseLogger
|
5
|
+
DATA_DIR_PATH = File.expand_path("../../../data/weight/", __FILE__)
|
6
|
+
|
7
|
+
def initialize(name, file_path = DATA_DIR_PATH)
|
8
|
+
file_path = "#{file_path}/#{name}.csv"
|
9
|
+
@name = name
|
10
|
+
super(file_path)
|
11
|
+
end
|
12
|
+
|
13
|
+
def add(weight, date = nil)
|
14
|
+
date = Date.today if date.nil?
|
15
|
+
line = [date, weight].join(',')
|
16
|
+
@io.write("#{line}\n")
|
17
|
+
end
|
18
|
+
|
19
|
+
def show(n = 10)
|
20
|
+
puts "#{@name}'s weights:"
|
21
|
+
formatted_rows(n).each do |line|
|
22
|
+
line = line.split(",")
|
23
|
+
puts "#{line[0]}: #{line[1]}g"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def formatted_rows(n)
|
28
|
+
@io.rewind
|
29
|
+
read_lines.reverse.first(n)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
data/lib/buncho.rb
ADDED
data/sig/buncho.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: buncho
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- tadaaki
|
8
|
+
bindir: bin
|
9
|
+
cert_chain: []
|
10
|
+
date: 2025-06-14 00:00:00.000000000 Z
|
11
|
+
dependencies: []
|
12
|
+
description: This is a Ruby gem for managing the body weight of Buncho.
|
13
|
+
executables:
|
14
|
+
- buncho
|
15
|
+
extensions: []
|
16
|
+
extra_rdoc_files: []
|
17
|
+
files:
|
18
|
+
- CHANGELOG.md
|
19
|
+
- LICENSE.txt
|
20
|
+
- README.md
|
21
|
+
- Rakefile
|
22
|
+
- bin/buncho
|
23
|
+
- data/.keep
|
24
|
+
- data/weight/.keep
|
25
|
+
- lib/buncho.rb
|
26
|
+
- lib/buncho/base_logger.rb
|
27
|
+
- lib/buncho/cli.rb
|
28
|
+
- lib/buncho/name_logger.rb
|
29
|
+
- lib/buncho/name_resolver.rb
|
30
|
+
- lib/buncho/version.rb
|
31
|
+
- lib/buncho/weight_logger.rb
|
32
|
+
- sig/buncho.rbs
|
33
|
+
homepage: https://kamazuni-marunomi.com/
|
34
|
+
licenses:
|
35
|
+
- MIT
|
36
|
+
metadata:
|
37
|
+
homepage_uri: https://kamazuni-marunomi.com/
|
38
|
+
source_code_uri: https://github.com/torinoko/buncho
|
39
|
+
changelog_uri: https://github.com/torinoko/buncho/blob/main/CHANGELOG.md
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.0.0
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
requirements: []
|
54
|
+
rubygems_version: 3.6.2
|
55
|
+
specification_version: 4
|
56
|
+
summary: gem for Buncho Body Weight Management
|
57
|
+
test_files: []
|