Class: AstrologicalForecast::Forecast

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

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Forecast

Returns a new instance of Forecast.



5
6
7
8
9
10
11
# File 'lib/astrological_forecast/forecast.rb', line 5

def initialize(params)
  @definition = params[:definition]
  @signs = params[:signs]
  @user_type = params[:user_type]
  @user_period = params[:user_period]
  @console = params[:console]
end

Instance Method Details

#data_forecastObject

получение прогноза



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/astrological_forecast/forecast.rb', line 14

def data_forecast
  # очистить экран
  puts "\e[H\e[2J"

  vars =
    { number: @definition['number'],
      name_ru: @definition['sign_ru'],
      name_en: @signs.keys[@definition['number'].to_i - 1],
      type: AstrologicalForecast::Facts::TYPES[AstrologicalForecast::Facts::TYPES.each_key(&:to_sym)[@user_type - 1]],
      time: AstrologicalForecast::Facts::PERIOD[AstrologicalForecast::Facts::PERIOD.each_key(&:to_sym)[@user_period - 1]] }

  begin
    intro = AstrologicalForecast::Introduction.init(vars)
    prediction = AstrologicalForecast::Prediction.new(vars).fetch_forecast!
  rescue SocketError => e
    puts "Ошибка соединения с сервером: #{e.message}"
    abort e.message
  end

  return forecast_results(intro, prediction) if @console

  intro.merge prediction
end

#forecast_results(intro, prediction) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/astrological_forecast/forecast.rb', line 38

def forecast_results(intro, prediction)
  puts <<~HOROSCOPE
    #{intro[:name]}:\n#{intro[:date]},\n#{intro[:head]}
    #{@definition["text"]}\n
    #{prediction[:head]}:\n\n#{prediction[:forecast]}
  HOROSCOPE
end