kisyo 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/kisyo/daily.rb +2 -4
- data/lib/kisyo/elements/day.rb +18 -9
- data/lib/kisyo/error.rb +1 -0
- data/lib/kisyo/version.rb +1 -1
- data/spec/kisyo/daily_spec.rb +27 -11
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d5eabd129f1b2191de6fdd0116779aa1104a091
|
4
|
+
data.tar.gz: 563fda3733d0e577057212146d90d23112801716
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0c75847c3f5fa34c177eeabb730291936e38457a531ad3f504a7aa8eec2251ef474222f021a8d0897c2c31b4241d1faa13a9f88596b631f35c0413aa797f694
|
7
|
+
data.tar.gz: d63e03065ce76e92f2b6a9de8846794c86f570062cefaa37c710e38622c20aec370a28cf84077f39e2774f61244fa1325b9279674f006ab72e3a56b15dac79f8
|
data/lib/kisyo/daily.rb
CHANGED
@@ -19,14 +19,12 @@ module Kisyo
|
|
19
19
|
doc = Nokogiri::HTML(content)
|
20
20
|
days = doc.css('div.a_print')
|
21
21
|
|
22
|
-
raise
|
22
|
+
raise WeatherInformationNotAvailable if days.size == 0
|
23
23
|
|
24
24
|
days.each do |el|
|
25
25
|
if el.text.to_i == date.day
|
26
26
|
tr = el.parent.parent
|
27
|
-
values = tr.css('td').map
|
28
|
-
td.text
|
29
|
-
end
|
27
|
+
values = tr.css('td').map(&:text)
|
30
28
|
|
31
29
|
return Element::Day.new(*values[1 .. -1])
|
32
30
|
end
|
data/lib/kisyo/elements/day.rb
CHANGED
@@ -31,18 +31,27 @@ module Kisyo
|
|
31
31
|
general_weather_condition_day,
|
32
32
|
general_weather_condition_night
|
33
33
|
)
|
34
|
-
@precipitation_total = precipitation_total
|
35
|
-
@precipitation_hourly_max = precipitation_hourly_max
|
36
|
-
@precipitation_10min_max = precipitation_10min_max
|
37
|
-
@temperature_avg = temperature_avg
|
38
|
-
@temperature_max = temperature_max
|
39
|
-
@temperature_min = temperature_min
|
40
|
-
@humidity_avg = humidity_avg
|
41
|
-
@humidity_min = humidity_min
|
42
|
-
@day_length = day_length
|
34
|
+
@precipitation_total = convert_value(precipitation_total)
|
35
|
+
@precipitation_hourly_max = convert_value(precipitation_hourly_max)
|
36
|
+
@precipitation_10min_max = convert_value(precipitation_10min_max)
|
37
|
+
@temperature_avg = convert_value(temperature_avg)
|
38
|
+
@temperature_max = convert_value(temperature_max)
|
39
|
+
@temperature_min = convert_value(temperature_min)
|
40
|
+
@humidity_avg = convert_value(humidity_avg)
|
41
|
+
@humidity_min = convert_value(humidity_min)
|
42
|
+
@day_length = convert_value(day_length)
|
43
43
|
@general_weather_condition_day = general_weather_condition_day
|
44
44
|
@general_weather_condition_night = general_weather_condition_night
|
45
45
|
end
|
46
|
+
|
47
|
+
def convert_value(value)
|
48
|
+
case value
|
49
|
+
when '--'
|
50
|
+
nil
|
51
|
+
else
|
52
|
+
value.to_f
|
53
|
+
end
|
54
|
+
end
|
46
55
|
end
|
47
56
|
end
|
48
57
|
end
|
data/lib/kisyo/error.rb
CHANGED
data/lib/kisyo/version.rb
CHANGED
data/spec/kisyo/daily_spec.rb
CHANGED
@@ -19,19 +19,22 @@ describe Kisyo::Daily do
|
|
19
19
|
'http://www.data.jma.go.jp/obd/stats/etrn/view/daily_s1.php?block_no=47662&day=01&month=11&prec_no=44&view=p1&year=2016'
|
20
20
|
}
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
to_return(:body => read_fixture_file('201611.html'))
|
26
|
-
end
|
22
|
+
let(:fixture_file_name) {
|
23
|
+
'201611.html'
|
24
|
+
}
|
27
25
|
|
26
|
+
before do
|
27
|
+
stub_request(:get, url).
|
28
|
+
to_return(:body => read_fixture_file(fixture_file_name))
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'information is available' do
|
28
32
|
it 'returns weather information for given day' do
|
29
33
|
info = daily.at(date)
|
30
34
|
|
31
35
|
expect(info.precipitation_total).to eql(1.5)
|
32
36
|
expect(info.precipitation_hourly_max).to eql(1.0)
|
33
37
|
expect(info.precipitation_10min_max).to eql(0.5)
|
34
|
-
expect(info.precipitation_10min_max).to eql(0.5)
|
35
38
|
expect(info.temperature_avg).to eql(10.9)
|
36
39
|
expect(info.temperature_max).to eql(12.2)
|
37
40
|
expect(info.temperature_min).to eql(8.6)
|
@@ -44,15 +47,28 @@ describe Kisyo::Daily do
|
|
44
47
|
end
|
45
48
|
|
46
49
|
context 'information is not available' do
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
end
|
50
|
+
let(:fixture_file_name) {
|
51
|
+
'ng.html'
|
52
|
+
}
|
51
53
|
|
52
54
|
it 'raises error' do
|
53
55
|
expect {
|
54
56
|
daily.at(date)
|
55
|
-
}.to raise_error(Kisyo::
|
57
|
+
}.to raise_error(Kisyo::WeatherInformationNotAvailable)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'value is "--"' do
|
62
|
+
let(:date) {
|
63
|
+
Date.parse('2016-11-04')
|
64
|
+
}
|
65
|
+
|
66
|
+
it '"--" is converted to nil' do
|
67
|
+
info = daily.at(date)
|
68
|
+
|
69
|
+
expect(info.precipitation_total).to be_nil
|
70
|
+
expect(info.precipitation_hourly_max).to be_nil
|
71
|
+
expect(info.precipitation_10min_max).to be_nil
|
56
72
|
end
|
57
73
|
end
|
58
74
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kisyo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- youpy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|