Newer
Older
Ruby / haru2.rb
@MASUKO Haru MASUKO Haru on 21 Dec 2024 2 KB 2024-12-21 23:31:10
require 'date'

# 星座と誕生石を定義
ZODIAC_SIGNS = {
  "牡羊座" => {start_date: Date.new(2022, 3, 21), end_date: Date.new(2022, 4, 19), stone: "ダイヤモンド"},
  "牡牛座" => {start_date: Date.new(2022, 4, 20), end_date: Date.new(2022, 5, 20), stone: "エメラルド"},
  "双子座" => {start_date: Date.new(2022, 5, 21), end_date: Date.new(2022, 6, 20), stone: "アレキサンドライト"},
  "蟹座" => {start_date: Date.new(2022, 6, 21), end_date: Date.new(2022, 7, 22), stone: "真珠"},
  "獅子座" => {start_date: Date.new(2022, 7, 23), end_date: Date.new(2022, 8, 22), stone: "ルビー"},
  "乙女座" => {start_date: Date.new(2022, 8, 23), end_date: Date.new(2022, 9, 22), stone: "サファイア"},
  "天秤座" => {start_date: Date.new(2022, 9, 23), end_date: Date.new(2022, 10, 22), stone: "オパール"},
  "蠍座" => {start_date: Date.new(2022, 10, 23), end_date: Date.new(2022, 11, 21), stone: "トパーズ"},
  "射手座" => {start_date: Date.new(2022, 11, 22), end_date: Date.new(2022, 12, 21), stone: "タンザナイト"},
  "山羊座" => {start_date: Date.new(2022, 12, 22), end_date: Date.new(2023, 1, 19), stone: "ガーネット"},
  "水瓶座" => {start_date: Date.new(2023, 1, 20), end_date: Date.new(2023, 2, 18), stone: "アメジスト"},
  "魚座" => {start_date: Date.new(2023, 2, 19), end_date: Date.new(2023, 3, 20), stone: "アクアマリン"}
}

# 今日の運勢の選択肢
FORTUNES = ["絶好調", "好調", "不調", "絶不調"]

# ユーザーから誕生日を取得
puts "誕生日を入力してください (例: 1990-04-25): "
birthday_str = gets.chomp
birthday = Date.parse(birthday_str)

# 星座と誕生石を判断
zodiac_sign = ZODIAC_SIGNS.find do |_, range|
  (range[:start_date].month == birthday.month && range[:start_date].day <= birthday.day) ||
  (range[:end_date].month == birthday.month && range[:end_date].day >= birthday.day) ||
  (range[:start_date].month < birthday.month && range[:end_date].month > birthday.month)
end

if zodiac_sign
  zodiac_name = zodiac_sign[0]
  birthstone = zodiac_sign[1][:stone]
  puts "あなたの星座は#{zodiac_name}で、誕生石は#{birthstone}です。"
else
  puts "誕生日から星座を判断できませんでした。"
end

# 今日の運勢をランダムに選ぶ
srand(birthday.day + birthday.month + birthday.year)  # 誕生日の数字を使ってシードを設定
today_fortune = FORTUNES.sample
puts "今日の運勢は: #{today_fortune}"