Class: AstrologicalForecast::DefinitionSign

Inherits:
Object
  • Object
show all
Defined in:
lib/astrological_forecast/definition_sign.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(date:) ⇒ DefinitionSign

Returns a new instance of DefinitionSign.



7
8
9
10
11
12
13
# File 'lib/astrological_forecast/definition_sign.rb', line 7

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

  @signs = sign
end

Instance Attribute Details

#definitionObject (readonly)

Returns the value of attribute definition.



5
6
7
# File 'lib/astrological_forecast/definition_sign.rb', line 5

def definition
  @definition
end

#signsObject (readonly)

Returns the value of attribute signs.



5
6
7
# File 'lib/astrological_forecast/definition_sign.rb', line 5

def signs
  @signs
end

Instance Method Details

#definition_sign_consoleObject

Определение знака зодиака по дате рождения через консоль



22
23
24
25
26
27
28
# File 'lib/astrological_forecast/definition_sign.rb', line 22

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

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

#definition_sign_handsObject

Raises:



30
31
32
33
34
# File 'lib/astrological_forecast/definition_sign.rb', line 30

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

  AstrologicalForecast::Facts.sign_identification(sign, @date)
end

#signObject



15
16
17
18
19
# File 'lib/astrological_forecast/definition_sign.rb', line 15

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