weather_pinpoint_jp 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module WeatherPinpointJp
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -92,6 +92,8 @@ module WeatherPinpointJp
92
92
  @weather << e.text.to_i
93
93
  end
94
94
 
95
+ @weather_3h = create_weather_3h(@weather)
96
+
95
97
  # temperature
96
98
  @temperature = []
97
99
  day.elements.each('temperature/hour') do |e|
@@ -105,7 +107,48 @@ module WeatherPinpointJp
105
107
  end
106
108
  end
107
109
 
108
- attr_reader :location, :start_time, :weather, :temperature, :precipitation
110
+ # 天気コードの強さを返す
111
+ def code_rank(a)
112
+ rank = {
113
+ 0 => 0,
114
+ 100 => 1,
115
+ 550 => 2,
116
+ 200 => 3,
117
+ 300 => 4,
118
+ 400 => 5,
119
+ 850 => 6,
120
+ }
121
+ return rank[a] if rank.key?(a)
122
+
123
+ return 10
124
+ end
125
+
126
+ # どちらの天気コードが影響をおよぼすか?比較
127
+ def compare_code(a, b)
128
+ return code_rank(a) <= code_rank(b)
129
+ end
130
+
131
+ # 3時間毎の天気コードに集約
132
+ def create_weather_3h(codes)
133
+ codes_3h = []
134
+ count = 0;
135
+ max_code = 0;
136
+ codes.each {|c|
137
+ if compare_code(max_code ,c)
138
+ max_code = c
139
+ end
140
+ count += 1
141
+ if count == 3
142
+ codes_3h << max_code
143
+ max_code = 0
144
+ count = 0
145
+ end
146
+ }
147
+
148
+ codes_3h
149
+ end
150
+
151
+ attr_reader :location, :start_time, :weather, :weather_3h, :temperature, :precipitation
109
152
  end
110
153
  end
111
154
 
File without changes
File without changes
File without changes
data/test/test_3h.rb ADDED
@@ -0,0 +1,31 @@
1
+ # -*- coding:utf-8 -*-
2
+ require 'rubygems'
3
+ require 'bundler/setup'
4
+ $:.unshift File.expand_path '../lib', File.dirname(__FILE__)
5
+ require 'minitest/autorun'
6
+
7
+ require 'weather_pinpoint_jp'
8
+
9
+ class Test3h < Minitest::Test
10
+ def setup
11
+ end
12
+
13
+ def test_load
14
+ f = WeatherPinpointJp.load("test_data", File.dirname(__FILE__) + "/test_data2.xml")
15
+ assert_equal f.nil?, false, "load() failed..."
16
+
17
+ assert_equal f.weather_3h.size, 10 # 32/3 = 10.66... => 10
18
+
19
+ assert_equal f.weather_3h[0], 100
20
+ assert_equal f.weather_3h[1], 200
21
+ assert_equal f.weather_3h[2], 300
22
+ assert_equal f.weather_3h[3], 400
23
+ assert_equal f.weather_3h[4], 500
24
+ assert_equal f.weather_3h[5], 850
25
+ assert_equal f.weather_3h[6], 200
26
+ assert_equal f.weather_3h[7], 300
27
+ assert_equal f.weather_3h[8], 400
28
+ assert_equal f.weather_3h[9], 850
29
+ end
30
+ end
31
+
data/test/test_data.xml CHANGED
@@ -34,10 +34,6 @@
34
34
  <hour>200</hour>
35
35
  <hour>300</hour>
36
36
  <hour>400</hour>
37
- <hour>100</hour>
38
- <hour>200</hour>
39
- <hour>300</hour>
40
- <hour>400</hour>
41
37
  </weather>
42
38
  <temperature>
43
39
  <hour>1</hour>
@@ -72,10 +68,6 @@
72
68
  <hour>30</hour>
73
69
  <hour>31</hour>
74
70
  <hour>32</hour>
75
- <hour>33</hour>
76
- <hour>34</hour>
77
- <hour>35</hour>
78
- <hour>36</hour>
79
71
  </temperature>
80
72
  <precipitation>
81
73
  <hour>11</hour>
@@ -110,10 +102,6 @@
110
102
  <hour>40</hour>
111
103
  <hour>41</hour>
112
104
  <hour>42</hour>
113
- <hour>43</hour>
114
- <hour>44</hour>
115
- <hour>45</hour>
116
- <hour>46</hour>
117
105
  </precipitation>
118
106
  </day>
119
107
  </data>
@@ -0,0 +1,108 @@
1
+ <weathernews>
2
+ <data>
3
+ <day startHour="13" startYear="2013" startMonth="11" startDate="12" startDay="2">
4
+ <weather>
5
+ <hour>100</hour>
6
+ <hour>100</hour>
7
+ <hour>100</hour>
8
+ <hour>100</hour>
9
+ <hour>100</hour>
10
+ <hour>200</hour>
11
+ <hour>100</hour>
12
+ <hour>100</hour>
13
+ <hour>300</hour>
14
+ <hour>100</hour>
15
+ <hour>100</hour>
16
+ <hour>400</hour>
17
+ <hour>100</hour>
18
+ <hour>100</hour>
19
+ <hour>500</hour>
20
+ <hour>100</hour>
21
+ <hour>100</hour>
22
+ <hour>850</hour>
23
+ <hour>200</hour>
24
+ <hour>200</hour>
25
+ <hour>200</hour>
26
+ <hour>200</hour>
27
+ <hour>200</hour>
28
+ <hour>300</hour>
29
+ <hour>200</hour>
30
+ <hour>200</hour>
31
+ <hour>400</hour>
32
+ <hour>300</hour>
33
+ <hour>300</hour>
34
+ <hour>850</hour>
35
+ <hour>100</hour>
36
+ <hour>100</hour>
37
+ </weather>
38
+ <temperature>
39
+ <hour>1</hour>
40
+ <hour>2</hour>
41
+ <hour>3</hour>
42
+ <hour>4</hour>
43
+ <hour>5</hour>
44
+ <hour>6</hour>
45
+ <hour>7</hour>
46
+ <hour>8</hour>
47
+ <hour>9</hour>
48
+ <hour>10</hour>
49
+ <hour>11</hour>
50
+ <hour>12</hour>
51
+ <hour>13</hour>
52
+ <hour>14</hour>
53
+ <hour>15</hour>
54
+ <hour>16</hour>
55
+ <hour>17</hour>
56
+ <hour>18</hour>
57
+ <hour>19</hour>
58
+ <hour>20</hour>
59
+ <hour>21</hour>
60
+ <hour>22</hour>
61
+ <hour>23</hour>
62
+ <hour>24</hour>
63
+ <hour>25</hour>
64
+ <hour>26</hour>
65
+ <hour>27</hour>
66
+ <hour>28</hour>
67
+ <hour>29</hour>
68
+ <hour>30</hour>
69
+ <hour>31</hour>
70
+ <hour>32</hour>
71
+ </temperature>
72
+ <precipitation>
73
+ <hour>11</hour>
74
+ <hour>12</hour>
75
+ <hour>13</hour>
76
+ <hour>14</hour>
77
+ <hour>15</hour>
78
+ <hour>16</hour>
79
+ <hour>17</hour>
80
+ <hour>18</hour>
81
+ <hour>19</hour>
82
+ <hour>20</hour>
83
+ <hour>21</hour>
84
+ <hour>22</hour>
85
+ <hour>23</hour>
86
+ <hour>24</hour>
87
+ <hour>25</hour>
88
+ <hour>26</hour>
89
+ <hour>27</hour>
90
+ <hour>28</hour>
91
+ <hour>29</hour>
92
+ <hour>30</hour>
93
+ <hour>31</hour>
94
+ <hour>32</hour>
95
+ <hour>33</hour>
96
+ <hour>34</hour>
97
+ <hour>35</hour>
98
+ <hour>36</hour>
99
+ <hour>37</hour>
100
+ <hour>38</hour>
101
+ <hour>39</hour>
102
+ <hour>40</hour>
103
+ <hour>41</hour>
104
+ <hour>42</hour>
105
+ </precipitation>
106
+ </day>
107
+ </data>
108
+ </weathernews>
data/test/test_load.rb CHANGED
@@ -40,19 +40,19 @@ class TestLoad < Minitest::Test
40
40
  assert_equal f.start_time, Time.new(2013, 11, 12, 13, 0, 0)
41
41
 
42
42
  # weather
43
- assert_equal f.weather.size, 36
43
+ assert_equal f.weather.size, 32
44
44
  f.weather.each_with_index {|w, i|
45
45
  w = ((i % 4) + 1) * 100
46
46
  }
47
47
 
48
48
  # temperature
49
- assert_equal f.temperature.size, 36
49
+ assert_equal f.temperature.size, 32
50
50
  f.temperature.each_with_index {|t, i|
51
51
  assert_equal t, i + 1
52
52
  }
53
53
 
54
54
  # precipitation
55
- assert_equal f.precipitation.size, 36
55
+ assert_equal f.precipitation.size, 32
56
56
  f.precipitation.each_with_index {|p, i|
57
57
  assert_equal p, i + 1 + 10
58
58
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: weather_pinpoint_jp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -73,11 +73,13 @@ files:
73
73
  - Rakefile
74
74
  - lib/weather_pinpoint_jp.rb
75
75
  - lib/weather_pinpoint_jp/version.rb
76
- - samples/address.rb
77
- - samples/postalcode.rb
78
- - samples/station.rb
76
+ - sample/address.rb
77
+ - sample/postalcode.rb
78
+ - sample/station.rb
79
+ - test/test_3h.rb
79
80
  - test/test_data.html
80
81
  - test/test_data.xml
82
+ - test/test_data2.xml
81
83
  - test/test_data_result.xml
82
84
  - test/test_load.rb
83
85
  - weather_pinpoint_jp.gemspec
@@ -107,7 +109,9 @@ signing_key:
107
109
  specification_version: 3
108
110
  summary: weather information library for ruby
109
111
  test_files:
112
+ - test/test_3h.rb
110
113
  - test/test_data.html
111
114
  - test/test_data.xml
115
+ - test/test_data2.xml
112
116
  - test/test_data_result.xml
113
117
  - test/test_load.rb