mets_advisor 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 920999ee59dc54cab29c42eebdeb3d38da34cd292f1387bf31705edc9655abd7
4
+ data.tar.gz: 461934c754b45243ea7c5285b8e17de740494d6485cfd14544d2bbae57a784ba
5
+ SHA512:
6
+ metadata.gz: da19aeac29ec36bfd286995a022adce486a3412f3261ea89b15d8cbfcfcf1235a968d95e9e8d28fb134a270d2c76b87097f15de264a0797b987e307ac130bbcc
7
+ data.tar.gz: cd76f87ad22ac11f47791c7cad86b0e34f11ae229c8e1baea05ed63354b977d40107d430608bd1f85537237adb3587a903f1fc1110eb603f7a6d0b74fe18a829
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.1
3
+
4
+ Style/StringLiterals:
5
+ EnforcedStyle: double_quotes
6
+
7
+ Style/StringLiteralsInInterpolation:
8
+ EnforcedStyle: double_quotes
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2025-11-26
4
+
5
+ - Initial release
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 hirokiej
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,93 @@
1
+ # METsAdvisor
2
+
3
+ MetsAdvisor is a command-line tool that calculates your weekly METs (Metabolic Equivalents) based on your daily steps and exercise habits. It helps you determine whether you are getting enough physical activity for maintaining good health, and provides suggestions for improvement.
4
+
5
+ ## What are METs?
6
+
7
+ METs are Metabolic Equivalents.
8
+
9
+ > METs (Metabolic Equivalents) are units used to express the intensity of physical activity.
10
+
11
+ > “One MET is defined as the energy cost of sitting quietly…
12
+ > moderate activity is about four times, and vigorous activity is about eight times higher.”
13
+ > — WHO: Global Physical Activity Questionnaire (GPAQ) Analysis Guide
14
+ > https://www.who.int/publications/i/item/9789240015128
15
+
16
+ In short:
17
+
18
+ - 1 MET = resting energy expenditure
19
+ - 4 METs = moderate activity
20
+ - 8 METs = vigorous activity
21
+
22
+ METs are used worldwide to evaluate physical activity levels.
23
+
24
+ ## Installation
25
+
26
+ Install the gem:
27
+
28
+ ```
29
+ gem install mets_advisor
30
+ ```
31
+
32
+ ## Usage
33
+
34
+ ```
35
+ mets_advisor
36
+ ```
37
+
38
+ The tool will guide you through:
39
+
40
+ 1. Language selection
41
+ 2. Daily average steps
42
+ 3. Weekly exercise frequency
43
+ 4. Exercise intensity and type
44
+ 5. Daily exercise duration
45
+
46
+ ## Examples
47
+
48
+ ```
49
+ Please select your language / 言語を選択してください
50
+ → 日本語
51
+ English
52
+ Français
53
+ Español
54
+ ```
55
+
56
+ ```
57
+ Please select your language / 言語を選択してください: English
58
+
59
+ What is your daily average steps per week?: 3000
60
+ How many days per week do you exercise?: 2
61
+
62
+ Choose the intensity of exercise you usually do: Moderate (e.g. brisk walking)
63
+
64
+ Choose the activity that applies to you: Slow jogging
65
+ How many minutes per day do you exercise in total?: 30
66
+
67
+ 🚨You are not getting enough exercise!🚨
68
+ ---------------------------------------------------
69
+ Your physical activity is lacking by 【10 METs】.
70
+ Increasing physical activity can reduce the risk of lifestyle diseases.
71
+ 💡Here is a guideline for the required weekly physical activity💡
72
+ ---------------------------------------------------
73
+ 🚶Walking(4 METs): 150+ min (avg 21 min/day)
74
+ 🏃Light Running(9 METs): 66+ min (avg 9 min/day)
75
+ ```
76
+
77
+ ## Development
78
+
79
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
80
+
81
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
82
+
83
+ ## Contributing
84
+
85
+ Bug reports and pull requests are welcome on GitHub at https://github.com/hirokiej/mets_advisor. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/hirokiej/mets_advisor/blob/main/CODE_OF_CONDUCT.md).
86
+
87
+ ## License
88
+
89
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
90
+
91
+ ## Code of Conduct
92
+
93
+ Everyone interacting in the MetsAdvisor project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/hirokiej/mets_advisor/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/test_*.rb"]
10
+ t.verbose = true
11
+ end
12
+
13
+ desc "Run tests with coverage"
14
+ task :test_coverage do
15
+ ENV['COVERAGE'] = 'true'
16
+ Rake::Task[:test].invoke
17
+ end
18
+
19
+ desc "Run specific test file"
20
+ task :test_file, [:file] do |t, args|
21
+ if args[:file]
22
+ ruby "-Ilib:test #{args[:file]}"
23
+ else
24
+ puts "Usage: rake test_file[test/test_mets.rb]"
25
+ end
26
+ end
27
+
28
+ task default: :test
data/exe/mets_advisor ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ lib = File.expand_path('../lib', __dir__)
5
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
+ require "mets_advisor"
7
+
8
+ MetsAdvisor.run
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'constants'
4
+ require_relative 'intensity_selector'
5
+ require_relative 'i18n'
6
+
7
+ module MetsAdvisor
8
+ class Activity
9
+ attr_reader :steps, :active_day, :activity_intensity, :activity_amount
10
+
11
+ def initialize(i18n, selector)
12
+ @i18n = i18n
13
+ @selector = selector
14
+ @steps = 0
15
+ @active_day = 0
16
+ @activity_intensity = 0
17
+ @activity_amount = 0
18
+ end
19
+
20
+ def prompt
21
+ @steps = input_daily_average_steps
22
+ @active_day = input_active_days
23
+ gather_activity_details
24
+ end
25
+
26
+ private
27
+
28
+ def input_daily_average_steps
29
+ @selector.ask(@i18n.t(:prompt_steps)) do |input|
30
+ validate_proper_number(input)
31
+ end
32
+ end
33
+
34
+ def input_active_days
35
+ @selector.ask(@i18n.t(:prompt_active_days)) do |input|
36
+ validate_active_day(input)
37
+ end
38
+ end
39
+
40
+ def input_daily_activity_minutes
41
+ @selector.ask(@i18n.t(:prompt_activity_minutes)) do |input|
42
+ validate_proper_number(input)
43
+ end
44
+ end
45
+
46
+ def gather_activity_details
47
+ if @active_day.zero?
48
+ @activity_intensity = 0
49
+ @activity_amount = 0
50
+ return
51
+ end
52
+
53
+ intensity_selector = IntensitySelector.new(@i18n, @selector)
54
+ intensity = intensity_selector.select_activity_intensity
55
+ @activity_intensity = intensity_selector.select_activity_levels(intensity)
56
+ @activity_amount = input_daily_activity_minutes
57
+ end
58
+
59
+ def validate_proper_number(input)
60
+ return @i18n.t(:error_empty) if input.strip.empty?
61
+ return @i18n.t(:error_number) unless input.match?(/^\d+$/)
62
+ true
63
+ end
64
+
65
+ def validate_active_day(input)
66
+ return @i18n.t(:error_empty) if input.strip.empty?
67
+ return @i18n.t(:error_number) unless input.match?(/^\d+$/)
68
+
69
+ number = input.to_i
70
+ return @i18n.t(:error_range) if number > ONE_WEEK || number < 0
71
+
72
+ true
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MetsAdvisor
4
+ DAILY_IDEAL_STEPS = 8000
5
+ STEP_METS = 3
6
+
7
+ HOURLY_MINUTES = 60
8
+ ONE_WEEK = 7
9
+
10
+ WEEKLY_IDEAL_METS = 23
11
+ SUFFICIENT_METS = 21
12
+ INSUFFICIENT_METS = 20
13
+ WALKING_METS = 4
14
+ RUNNING_METS = 9
15
+ end
@@ -0,0 +1,115 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MetsAdvisor
4
+ class I18n
5
+ TRANSLATIONS = {
6
+ 'ja' => {
7
+ prompt_steps: '1週間の歩数を1日平均で教えてください',
8
+ prompt_active_days: '1週間に何日間運動をしていますか?',
9
+ prompt_activity_minutes: 'その運動は1日合計で何分ほどですか?',
10
+ error_number: '数字のみを入力してください',
11
+ error_empty: '数字を入力してください',
12
+ error_range: '0−7の数字を入力してください',
13
+ ideal_title: '🎉あなたの身体活動量は理想値を上回っています!🎉',
14
+ ideal_mets: 'あなたの身体活動量は【%{total_mets} METs】です。',
15
+ ideal_message: '素晴らしいですね!これからもこの身体活動量を続け、健康を維持してください!',
16
+ sufficient_title: '🙆‍♀️あなたの身体活動量は健康維持に適しています🙆‍♀️',
17
+ sufficient_shortage: '理想値まで残り【%{mets_shortage} METs】です。',
18
+ sufficient_suggestion: '💡以下を取り入れると理想的な1週間の身体活動量となります💡',
19
+ insufficient_title: '🚨あなたは運動不足です!🚨',
20
+ insufficient_shortage: 'あなたの身体活動量は【%{mets_shortage} METs】不足しています。',
21
+ insufficient_message: '身体活動量を増やすことで生活習慣病のリスクを減らせます。',
22
+ insufficient_suggestion: '💡以下が1週間で必要な身体活動量の目安です💡',
23
+ walking: '🚶ウォーキング(4メッツ): %{minutes}分以上(1日あたり%{daily}分)',
24
+ running: '🏃軽いランニング(9メッツ): %{minutes}分以上(1日あたり%{daily}分)',
25
+ separator: '---------------------------------------------------'
26
+ },
27
+ 'en' => {
28
+ prompt_steps: 'What is your daily average steps per week?',
29
+ prompt_active_days: 'How many days per week do you exercise?',
30
+ prompt_activity_minutes: 'How many minutes per day do you exercise in total?',
31
+ error_number: 'Enter numbers only',
32
+ error_empty: 'Enter a number',
33
+ error_range: 'Enter a number between 0-7',
34
+ ideal_title: '🎉Your physical activity level exceeds the ideal value!🎉',
35
+ ideal_mets: 'Your physical activity level is 【%{total_mets} METs】.',
36
+ ideal_message: 'Excellent! Keep up this level of physical activity to maintain your health!',
37
+ sufficient_title: '🙆‍♀️Your physical activity level is suitable for health maintenance🙆‍♀️',
38
+ sufficient_shortage: '【%{mets_shortage} METs】 remaining to reach the ideal value.',
39
+ sufficient_suggestion: '💡The following will help you achieve the ideal weekly physical activity💡',
40
+ insufficient_title: '🚨You are not getting enough exercise!🚨',
41
+ insufficient_shortage: 'Your physical activity is lacking by 【%{mets_shortage} METs】.',
42
+ insufficient_message: 'Increasing physical activity can reduce the risk of lifestyle diseases.',
43
+ insufficient_suggestion: '💡Here is a guideline for the required weekly physical activity💡',
44
+ walking: '🚶Walking(4 METs): %{minutes}+ min (avg %{daily} min/day)',
45
+ running: '🏃Light Running(9 METs): %{minutes}+ min (avg %{daily} min/day)',
46
+ separator: '---------------------------------------------------'
47
+ },
48
+ 'fr' => {
49
+ prompt_steps: 'Quelle est votre moyenne quotidienne de pas par semaine?',
50
+ prompt_active_days: 'Combien de jours par semaine faites-vous de l\'exercice?',
51
+ prompt_activity_minutes: 'Combien de minutes par jour faites-vous de l\'exercice au total?',
52
+ error_number: 'Entrer uniquement des chiffres',
53
+ error_empty: 'Entrer un nombre',
54
+ error_range: 'Entrer un nombre entre 0 et 7',
55
+ ideal_title: '🎉Votre niveau d\'activité physique dépasse la valeur idéale!🎉',
56
+ ideal_mets: 'Votre niveau d\'activité physique est de 【%{total_mets} METs】.',
57
+ ideal_message: 'Excellent! Continuez ce niveau d\'activité physique pour maintenir votre santé!',
58
+ sufficient_title: '🙆‍♀️Votre niveau d\'activité physique convient au maintien de la santé🙆‍♀️',
59
+ sufficient_shortage: '【%{mets_shortage} METs】 restant pour atteindre la valeur idéale.',
60
+ sufficient_suggestion: '💡Les activités suivantes vous aideront à atteindre l\'activité physique hebdomadaire idéale💡',
61
+ insufficient_title: '🚨Vous ne faites pas assez d\'exercice!🚨',
62
+ insufficient_shortage: 'Votre activité physique manque de 【%{mets_shortage} METs】.',
63
+ insufficient_message: 'Augmenter l\'activité physique peut réduire le risque de maladies liées au mode de vie.',
64
+ insufficient_suggestion: '💡Voici un guide pour l\'activité physique hebdomadaire requise💡',
65
+ walking: '🚶Marche(4 METs): %{minutes}+ min (moy. %{daily} min/jour)',
66
+ running: '🏃Course légère(9 METs): %{minutes}+ min (moy. %{daily} min/jour)',
67
+ separator: '---------------------------------------------------'
68
+ },
69
+ 'es' => {
70
+ prompt_steps: '¿Cuál es tu promedio diario de pasos por semana?',
71
+ prompt_active_days: '¿Cuántos días a la semana haces ejercicio?',
72
+ prompt_activity_minutes: '¿Cuántos minutos por día haces ejercicio en total?',
73
+ error_number: 'Ingresa solo números',
74
+ error_empty: 'Ingresa un número',
75
+ error_range: 'Ingresa un número entre 0-7',
76
+ ideal_title: '🎉¡Tu nivel de actividad física supera el valor ideal!🎉',
77
+ ideal_mets: 'Tu nivel de actividad física es 【%{total_mets} METs】.',
78
+ ideal_message: '¡Excelente! ¡Mantén este nivel de actividad física para mantener tu salud!',
79
+ sufficient_title: '🙆‍♀️Tu nivel de actividad física es adecuado para el mantenimiento de la salud🙆‍♀️',
80
+ sufficient_shortage: '【%{mets_shortage} METs】 restantes para alcanzar el valor ideal.',
81
+ sufficient_suggestion: '💡Lo siguiente te ayudará a lograr la actividad física semanal ideal💡',
82
+ insufficient_title: '🚨¡No estás haciendo suficiente ejercicio!🚨',
83
+ insufficient_shortage: 'Tu actividad física carece de 【%{mets_shortage} METs】.',
84
+ insufficient_message: 'Aumentar la actividad física puede reducir el riesgo de enfermedades del estilo de vida.',
85
+ insufficient_suggestion: '💡Aquí hay una guía para la actividad física semanal requerida💡',
86
+ walking: '🚶Caminar(4 METs): %{minutes}+ min (prom. %{daily} min/día)',
87
+ running: '🏃Correr ligero(9 METs): %{minutes}+ min (prom. %{daily} min/día)',
88
+ separator: '---------------------------------------------------'
89
+ }
90
+ }.freeze
91
+
92
+ attr_reader :locale
93
+
94
+ def initialize(locale = 'ja')
95
+ @locale = locale
96
+ end
97
+
98
+ def t(key, **options)
99
+ text = TRANSLATIONS[@locale][key] || TRANSLATIONS['en'][key] || key.to_s
100
+ options.each do |k, v|
101
+ text = text.gsub("%{#{k}}", v.to_s)
102
+ end
103
+ text
104
+ end
105
+
106
+ def self.available_locales
107
+ {
108
+ 'ja' => '日本語',
109
+ 'en' => 'English',
110
+ 'fr' => 'Français',
111
+ 'es' => 'Español'
112
+ }
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,144 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'i18n'
4
+
5
+ module MetsAdvisor
6
+ class IntensitySelector
7
+ INTENSITY_TRANSLATIONS = {
8
+ 'ja' => {
9
+ prompt_intensity: '運動の強度を選んでください',
10
+ light: '軽度(徒歩・ピラティスなど)',
11
+ moderate: '中程度(やや早歩きなど)',
12
+ vigorous: '強度(ジョギング・ランニング・サイクリングなど)',
13
+ prompt_level: '以下から該当する活動を選んでください',
14
+ error_choice: '1から選択肢の数字を入力してください'
15
+ },
16
+ 'en' => {
17
+ prompt_intensity: 'Choose the intensity of exercise you usually do',
18
+ light: 'Light (e.g. walking, pilates)',
19
+ moderate: 'Moderate (e.g. brisk walking)',
20
+ vigorous: 'Vigorous (e.g. jogging, running, cycling)',
21
+ prompt_level: 'Choose the activity that applies to you',
22
+ error_choice: 'Please enter a number from 1 to the number of choices'
23
+ },
24
+ 'fr' => {
25
+ prompt_intensity: 'Choisissez l\'intensité de votre activité physique',
26
+ light: 'Légère (ex : marche lente, pilates)',
27
+ moderate: 'Modérée (ex : marche rapide)',
28
+ vigorous: 'Élevée (ex : jogging, course, vélo)',
29
+ prompt_level: 'Sélectionnez l\'activité qui vous correspond',
30
+ error_choice: 'Veuillez entrer un numéro de 1 au nombre de choix'
31
+ },
32
+ 'es' => {
33
+ prompt_intensity: 'Elige la intensidad del ejercicio que sueles hacer',
34
+ light: 'Ligera (ej. caminar, pilates)',
35
+ moderate: 'Moderada (ej. caminata rápida)',
36
+ vigorous: 'Vigorosa (ej. trotar, correr, ciclismo)',
37
+ prompt_level: 'Elige la actividad que se aplica a ti',
38
+ error_choice: 'Por favor ingresa un número del 1 al número de opciones'
39
+ }
40
+ }.freeze
41
+
42
+ # METs値の定義
43
+ LIGHT_ACTIVITIES = {
44
+ 'ja' => {
45
+ 'ゆったり歩く・ピラティス' => 3.0,
46
+ '少し速めに歩く' => 4.0
47
+ },
48
+ 'en' => {
49
+ 'Easy walking / Pilates' => 3.0,
50
+ 'Brisk walking (slightly faster)' => 4.0
51
+ },
52
+ 'fr' => {
53
+ 'Marche tranquille / Pilates' => 3.0,
54
+ 'Marche un peu rapide' => 4.0
55
+ },
56
+ 'es' => {
57
+ 'Caminar tranquilo / Pilates' => 3.0,
58
+ 'Caminar algo rápido' => 4.0
59
+ }
60
+ }.freeze
61
+
62
+ MODERATE_ACTIVITIES = {
63
+ 'ja' => {
64
+ 'かなり速い歩行' => 5.0,
65
+ 'ゆっくりジョギング' => 6.0,
66
+ 'ジョギング' => 7.0
67
+ },
68
+ 'en' => {
69
+ 'Fast walking' => 5.0,
70
+ 'Slow jogging' => 6.0,
71
+ 'Jogging' => 7.0
72
+ },
73
+ 'fr' => {
74
+ 'Marche rapide' => 5.0,
75
+ 'Jogging lent' => 6.0,
76
+ 'Jogging' => 7.0
77
+ },
78
+ 'es' => {
79
+ 'Caminar rápido' => 5.0,
80
+ 'Trote lento' => 6.0,
81
+ 'Trotar' => 7.0
82
+ }
83
+ }.freeze
84
+
85
+ VIGOROUS_ACTIVITIES = {
86
+ 'ja' => {
87
+ 'サイクリング' => 8.0,
88
+ 'ランニング(1km8分ペース)' => 9.0,
89
+ 'ランニング(1km6分ペース)' => 10.0,
90
+ '非常に激しい運動' => 15.0
91
+ },
92
+ 'en' => {
93
+ 'Cycling' => 8.0,
94
+ 'Running (8 min/km pace ≒ 9:39 min/mile)' => 9.0,
95
+ 'Running (6 min/km pace ≒ 12:52 min/mile)' => 10.0,
96
+ 'Very vigorous exercise' => 15.0
97
+ },
98
+ 'fr' => {
99
+ 'Cyclisme' => 8.0,
100
+ 'Course (8 min/km)' => 9.0,
101
+ 'Course (6 min/km)' => 10.0,
102
+ 'Exercice très intense' => 15.0
103
+ },
104
+ 'es' => {
105
+ 'Ciclismo' => 8.0,
106
+ 'Correr (8 min/km)' => 9.0,
107
+ 'Correr (6 min/km)' => 10.0,
108
+ 'Ejercicio muy intenso' => 15.0
109
+ }
110
+ }.freeze
111
+
112
+ def initialize(i18n, selector)
113
+ @i18n = i18n
114
+ @selector = selector
115
+ @locale = i18n.locale
116
+ end
117
+
118
+ def select_activity_intensity
119
+ choices = [t(:light), t(:moderate), t(:vigorous)]
120
+ @selector.select(t(:prompt_intensity), choices) + 1
121
+ end
122
+
123
+ def select_activity_levels(intensity)
124
+ activities = case intensity
125
+ when 1
126
+ LIGHT_ACTIVITIES[@locale]
127
+ when 2
128
+ MODERATE_ACTIVITIES[@locale]
129
+ when 3
130
+ VIGOROUS_ACTIVITIES[@locale]
131
+ end
132
+
133
+ choices = activities.keys
134
+ index = @selector.select(t(:prompt_level), choices)
135
+ activities.values[index]
136
+ end
137
+
138
+ private
139
+
140
+ def t(key)
141
+ INTENSITY_TRANSLATIONS[@locale][key] || INTENSITY_TRANSLATIONS['en'][key] || key.to_s
142
+ end
143
+ end
144
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'constants'
4
+
5
+ module MetsAdvisor
6
+ class Mets
7
+ attr_reader :step_mets, :weekly_mets, :total_mets
8
+
9
+ def initialize(steps, active_day, activity_intensity, activity_amount)
10
+ @step_mets = calc_step_mets(steps)
11
+ @weekly_mets = calc_weekly_activity_mets(active_day, activity_intensity, activity_amount)
12
+ @total_mets = (@step_mets + @weekly_mets).to_i
13
+ end
14
+
15
+ private
16
+
17
+ def calc_step_mets(steps)
18
+ weekly_steps = steps * ONE_WEEK
19
+ ((weekly_steps.to_f / DAILY_IDEAL_STEPS) * STEP_METS).to_i
20
+ end
21
+
22
+ def calc_weekly_activity_mets(active_day, activity_intensity, activity_amount)
23
+ activity_mets = (activity_amount.to_f / HOURLY_MINUTES) * activity_intensity
24
+ active_day * activity_mets
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require_relative 'constants'
5
+
6
+ module MetsAdvisor
7
+ class Result
8
+ def initialize(total_mets, i18n)
9
+ @total_mets = total_mets
10
+ @mets_shortage = WEEKLY_IDEAL_METS - @total_mets
11
+ @i18n = i18n
12
+ end
13
+
14
+ def display
15
+ if ideal_mets?
16
+ display_ideal
17
+ elsif sufficient_mets?
18
+ display_sufficient
19
+ elsif insufficient_mets?
20
+ display_insufficient
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def ideal_mets?
27
+ @total_mets >= WEEKLY_IDEAL_METS
28
+ end
29
+
30
+ def sufficient_mets?
31
+ @total_mets == SUFFICIENT_METS || @total_mets == SUFFICIENT_METS + 1
32
+ end
33
+
34
+ def insufficient_mets?
35
+ @total_mets <= INSUFFICIENT_METS
36
+ end
37
+
38
+ def display_ideal
39
+ puts @i18n.t(:ideal_title)
40
+ puts @i18n.t(:separator)
41
+ puts @i18n.t(:ideal_mets, total_mets: @total_mets)
42
+ puts @i18n.t(:ideal_message)
43
+ end
44
+
45
+ def display_sufficient
46
+ puts @i18n.t(:sufficient_title)
47
+ puts @i18n.t(:separator)
48
+ puts @i18n.t(:ideal_mets, total_mets: @total_mets)
49
+ puts @i18n.t(:sufficient_shortage, mets_shortage: @mets_shortage)
50
+ puts @i18n.t(:sufficient_suggestion)
51
+ puts @i18n.t(:separator)
52
+ suggest_required_exercise
53
+ end
54
+
55
+ def display_insufficient
56
+ puts @i18n.t(:insufficient_title)
57
+ puts @i18n.t(:separator)
58
+ puts @i18n.t(:insufficient_shortage, mets_shortage: @mets_shortage)
59
+ puts @i18n.t(:insufficient_message)
60
+ puts @i18n.t(:insufficient_suggestion)
61
+ puts @i18n.t(:separator)
62
+ suggest_required_exercise
63
+ end
64
+
65
+ def calc_walking_minutes
66
+ ((@mets_shortage.to_f / WALKING_METS) * HOURLY_MINUTES).to_i
67
+ end
68
+
69
+ def calc_running_minutes
70
+ ((@mets_shortage.to_f / RUNNING_METS) * HOURLY_MINUTES).to_i
71
+ end
72
+
73
+ def suggest_required_exercise
74
+ suggest_walking_minutes = calc_walking_minutes
75
+ suggest_running_minutes = calc_running_minutes
76
+
77
+ puts @i18n.t(:walking,
78
+ minutes: suggest_walking_minutes,
79
+ daily: suggest_walking_minutes / ONE_WEEK)
80
+ puts @i18n.t(:running,
81
+ minutes: suggest_running_minutes,
82
+ daily: suggest_running_minutes / ONE_WEEK)
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'io/console'
4
+
5
+ module MetsAdvisor
6
+ class Selector
7
+ ARROW_UP = "\e[A"
8
+ ARROW_DOWN = "\e[B"
9
+ ENTER = "\r"
10
+
11
+ def initialize
12
+ @selected_index = 0
13
+ end
14
+
15
+ def select(prompt, choices)
16
+ puts ''
17
+ puts prompt
18
+ display_choices(choices, initial: true)
19
+
20
+ loop do
21
+ key = read_key
22
+
23
+ case key
24
+ when ARROW_UP
25
+ @selected_index = (@selected_index - 1) % choices.length
26
+ display_choices(choices)
27
+ when ARROW_DOWN
28
+ @selected_index = (@selected_index + 1) % choices.length
29
+ display_choices(choices)
30
+ when ENTER
31
+ print "\e[#{choices.length + 1}A"
32
+ print "\e[J"
33
+
34
+ puts "#{prompt}: #{choices[@selected_index]}"
35
+ return @selected_index
36
+ end
37
+ end
38
+ end
39
+
40
+ def ask(prompt, &validation)
41
+ loop do
42
+ print "#{prompt}: "
43
+ input = gets.chomp
44
+
45
+ if validation
46
+ result = validation.call(input)
47
+ if result == true
48
+ return input.to_i
49
+ else
50
+ puts result
51
+ end
52
+ else
53
+ return input.to_i
54
+ end
55
+ end
56
+ end
57
+
58
+ private
59
+
60
+ def display_choices(choices, initial: false)
61
+ clear_choices(choices.length) unless initial
62
+
63
+ choices.each_with_index do |choice, index|
64
+ if index == @selected_index
65
+ puts "→ \e[1m#{choice}\e[0m" # 太字で表示
66
+ else
67
+ puts " #{choice}"
68
+ end
69
+ end
70
+ end
71
+
72
+ def clear_choices(count)
73
+ print "\e[#{count}A" # カーソルを上に移動
74
+ print "\e[J" # カーソル以下をクリア
75
+ end
76
+
77
+ def read_key
78
+ $stdin.raw do |io|
79
+ input = io.getc
80
+ if input == "\e"
81
+ input << io.read_nonblock(2) rescue nil
82
+ end
83
+ input
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MetsAdvisor
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "mets_advisor/version"
4
+ require_relative 'mets_advisor/activity'
5
+ require_relative 'mets_advisor/mets'
6
+ require_relative 'mets_advisor/result'
7
+ require_relative 'mets_advisor/i18n'
8
+ require_relative 'mets_advisor/selector'
9
+
10
+ module MetsAdvisor
11
+ def self.run
12
+ selector = Selector.new
13
+
14
+ # 言語選択
15
+ locale_choices = I18n.available_locales.values
16
+ locale_index = selector.select(
17
+ 'Please select your language / 言語を選択してください',
18
+ locale_choices
19
+ )
20
+ locale_choice = I18n.available_locales.keys[locale_index]
21
+
22
+ i18n = I18n.new(locale_choice)
23
+ puts ''
24
+
25
+ # アクティビティ入力
26
+ activity = Activity.new(i18n, selector)
27
+ activity.prompt
28
+
29
+ # METs計算
30
+ mets = Mets.new(
31
+ activity.steps,
32
+ activity.active_day,
33
+ activity.activity_intensity,
34
+ activity.activity_amount
35
+ )
36
+
37
+ # 結果表示
38
+ puts ''
39
+ result = Result.new(mets.total_mets, i18n)
40
+ result.display
41
+ end
42
+ end
43
+
44
+ # 実行
45
+ MetsAdvisor.run if __FILE__ == $PROGRAM_NAME
@@ -0,0 +1,4 @@
1
+ module MetsAdvisor
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mets_advisor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - hirokiej
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 2025-11-26 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: MetsAdvisor helps users estimate weekly METs based on activity input,
13
+ supporting health maintenance.
14
+ email:
15
+ - 123009866+hirokiej@users.noreply.github.com
16
+ executables:
17
+ - mets_advisor
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".rubocop.yml"
22
+ - CHANGELOG.md
23
+ - CODE_OF_CONDUCT.md
24
+ - LICENSE.txt
25
+ - README.md
26
+ - Rakefile
27
+ - exe/mets_advisor
28
+ - lib/mets_advisor.rb
29
+ - lib/mets_advisor/activity.rb
30
+ - lib/mets_advisor/constants.rb
31
+ - lib/mets_advisor/i18n.rb
32
+ - lib/mets_advisor/intensity_selector.rb
33
+ - lib/mets_advisor/mets.rb
34
+ - lib/mets_advisor/result.rb
35
+ - lib/mets_advisor/selector.rb
36
+ - lib/mets_advisor/version.rb
37
+ - sig/mets_advisor.rbs
38
+ homepage: https://github.com/hirokiej/mets_advisor
39
+ licenses:
40
+ - MIT
41
+ metadata:
42
+ homepage_uri: https://github.com/hirokiej/mets_advisor
43
+ source_code_uri: https://github.com/hirokiej/mets_advisor
44
+ changelog_uri: https://github.com/hirokiej/mets_advisor/blob/main/CHANGELOG.md
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 3.1.0
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubygems_version: 3.6.2
60
+ specification_version: 4
61
+ summary: CLI tool to calculate METs(Metabolic Equivalents) for physical activities
62
+ test_files: []