Class: Meteoservice::ReadData

Inherits:
Object
  • Object
show all
Defined in:
lib/meteoservice/read_data.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(forecasts) ⇒ ReadData

Returns a new instance of ReadData.



67
68
69
# File 'lib/meteoservice/read_data.rb', line 67

def initialize(forecasts)
  @forecasts = forecasts
end

Class Method Details

.from_array(doc) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/meteoservice/read_data.rb', line 5

def self.from_array(doc)
  include Meteoservice::Constants

  forecasts = doc.map do |prediction|
    predict_data = {}

    # дата "год, месяц, день, час, день недели"
    data = KEYS_DATA.map do |key|
      prediction[key].to_i
    end

    predict_data[:data] = data

    # атмосферные явления
    phenomena = KEYS_PHENOMENA.map do |key|
      prediction['PHENOMENA'][key].to_i
    end

    predict_data[:phenomena] = phenomena

    # атмосферное давление
    pressure = KEYS_LIMIT.map do |key|
      prediction['PRESSURE'][key].to_i
    end

    predict_data[:pressure] = pressure

    # температура
    temperature = KEYS_LIMIT.map do |key|
      prediction['TEMPERATURE'][key].to_i
    end

    predict_data[:temperature] = temperature

    # относительная влажность воздуха
    relwet = KEYS_LIMIT.map do |key|
      prediction['RELWET'][key].to_i
    end

    predict_data[:relwet] = relwet

    # комфорт - температура воздуха по ощущению одетого по сезону
    # человека, выходящего на улицу
    heat = KEYS_LIMIT.map do |key|
      prediction['HEAT'][key].to_i
    end

    predict_data[:heat] = heat

    # приземный ветер
    max_wind = prediction['WIND']['max']
    min_wind = prediction['WIND']['min']
    direction_wind = prediction['WIND']['direction']

    predict_data[:wind] = [min_wind, max_wind, direction_wind]

    Meteoservice::Meteo.new(predict_data)
  end

  new(forecasts)
end

Instance Method Details

#to_aObject



71
72
73
# File 'lib/meteoservice/read_data.rb', line 71

def to_a
  @forecasts
end