Sha256: 2549ccc1c97bc54a0a1dd3a0d3f5aa4c52cd7b5d4e7b70e78e58e592e0a57811

Contents?: true

Size: 1.17 KB

Versions: 7

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true

module AstrologicalForecast
  class DefinitionSign
    attr_reader :definition, :signs

    def initialize(date:)
      @date = date
      # Номер знака зодиака
      @definition = date.nil? ? definition_sign_console : definition_sign_hands

      @signs = sign
    end

    def sign
      # Прочитаем файл со знаками зодиака и запишем данные в ассоциативный хэш-массив
      file = File.read("#{__dir__}/data/signs.json", encoding: 'utf-8')
      JSON.parse(file)
    end

    # Определение знака зодиака по дате рождения через консоль
    def definition_sign_console
      # Запрос у пользователя даты его рождения
      puts 'Когда вы родились (укажите дату в формате ДД.ММ, например, 31.12)'
      user_date_string = $stdin.gets.chomp

      AstrologicalForecast::Facts.sign_identification(sign, user_date_string)
    end

    def definition_sign_hands
      raise IncorrectDate unless @date.match?(/\A(\d{2})\.(\d{2})\z/)

      @date
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
astrological_forecast-1.3.5 lib/astrological_forecast/definition_sign.rb
astrological_forecast-1.3.4 lib/astrological_forecast/definition_sign.rb
astrological_forecast-1.3.3 lib/astrological_forecast/definition_sign.rb
astrological_forecast-1.2.3 lib/astrological_forecast/definition_sign.rb
astrological_forecast-1.2.2 lib/astrological_forecast/definition_sign.rb
astrological_forecast-1.2.1 lib/astrological_forecast/definition_sign.rb
astrological_forecast-1.2.0 lib/astrological_forecast/definition_sign.rb