kisyo 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c64fc33cac93f764fed948343fadfddb24f3baf6
4
- data.tar.gz: 219f910e4b428373b6d0c31fdf7116720f214030
3
+ metadata.gz: 6d5eabd129f1b2191de6fdd0116779aa1104a091
4
+ data.tar.gz: 563fda3733d0e577057212146d90d23112801716
5
5
  SHA512:
6
- metadata.gz: 55b39ac75b8c72539adcb780194d8d26439398d141c73193070b66e3e31c3f879d986ee0522f8421cbe6062097cfd0d535d6b51a03dfd11c2393f4284517014a
7
- data.tar.gz: 401344277d57491d9f47e0aa93570974b1eb5236222c74fcfcfd2ae0a1f3ae3a42b98b09608759a73ea25cdafbcba2f74984e975bd650b8e9f901c8e0d67984a
6
+ metadata.gz: f0c75847c3f5fa34c177eeabb730291936e38457a531ad3f504a7aa8eec2251ef474222f021a8d0897c2c31b4241d1faa13a9f88596b631f35c0413aa797f694
7
+ data.tar.gz: d63e03065ce76e92f2b6a9de8846794c86f570062cefaa37c710e38622c20aec370a28cf84077f39e2774f61244fa1325b9279674f006ab72e3a56b15dac79f8
@@ -19,14 +19,12 @@ module Kisyo
19
19
  doc = Nokogiri::HTML(content)
20
20
  days = doc.css('div.a_print')
21
21
 
22
- raise Error.new('invalid date') if days.size == 0
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 do |td|
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
@@ -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.to_f
35
- @precipitation_hourly_max = precipitation_hourly_max.to_f
36
- @precipitation_10min_max = precipitation_10min_max.to_f
37
- @temperature_avg = temperature_avg.to_f
38
- @temperature_max = temperature_max.to_f
39
- @temperature_min = temperature_min.to_f
40
- @humidity_avg = humidity_avg.to_f
41
- @humidity_min = humidity_min.to_f
42
- @day_length = day_length.to_f
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
@@ -1,3 +1,4 @@
1
1
  module Kisyo
2
2
  class Error < StandardError; end
3
+ class WeatherInformationNotAvailable < Error; end
3
4
  end
@@ -1,3 +1,3 @@
1
1
  module Kisyo
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -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
- context 'information is available' do
23
- before do
24
- stub_request(:get, url).
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
- before do
48
- stub_request(:get, url).
49
- to_return(:body => read_fixture_file('ng.html'))
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::Error, 'invalid date')
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.1
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-08 00:00:00.000000000 Z
11
+ date: 2016-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri