File Coverage

blib/lib/Weather/YR/LocationForecast/Day.pm
Criterion Covered Total %
statement 6 106 5.6
branch 0 22 0.0
condition 0 6 0.0
subroutine 2 21 9.5
pod n/a
total 8 155 5.1


line stmt bran cond sub pod time code
1             package Weather::YR::LocationForecast::Day;
2 3     3   17 use Moose;
  3         42  
  3         19  
3 3     3   15558 use namespace::autoclean;
  3         6  
  3         25  
4              
5             extends 'Weather::YR::Day';
6              
7             =head1 NAME
8              
9             Weather::YR::LocationForecast::Day - Class that holds weather data for one day.
10              
11             =head1 DESCRIPTION
12              
13             Don't use this class directly. Instead, access it via L<Weather::YR> and
14             L<Weather::YR::LocationForecast>.
15              
16             =cut
17              
18             # Temperature
19             has 'temperatures' => ( isa => 'ArrayRef[Weather::YR::Model::Temperature]', is => 'ro', lazy_build => 1 );
20             has 'temperature' => ( isa => 'Weather::YR::Model::Temperature', is => 'ro', lazy_build => 1 );
21              
22             # Precipitation
23             has 'precipitations' => ( isa => 'ArrayRef[Weather::YR::Model::Precipitation]', is => 'ro', lazy_build => 1 );
24             has 'precipitation' => ( isa => 'Weather::YR::Model::Precipitation', is => 'ro', lazy_build => 1 );
25              
26             # Wind direction
27             has 'wind_directions' => ( isa => 'ArrayRef[Weather::YR::Model::WindDirection]', is => 'ro', lazy_build => 1 );
28             has 'wind_direction' => ( isa => 'Weather::YR::Model::WindDirection', is => 'ro', lazy_build => 1 );
29              
30             # Wind speed
31             has 'wind_speeds' => ( isa => 'ArrayRef[Weather::YR::Model::WindSpeed]', is => 'ro', lazy_build => 1 );
32             has 'wind_speed' => ( isa => 'Weather::YR::Model::WindSpeed', is => 'ro', lazy_build => 1 );
33              
34             # Humidity
35             has 'humidities' => ( isa => 'ArrayRef[Weather::YR::Model::Humidity]', is => 'ro', lazy_build => 1 );
36             has 'humidity' => ( isa => 'Weather::YR::Model::Humidity', is => 'ro', lazy_build => 1 );
37              
38             # Pressure
39             has 'pressures' => ( isa => 'ArrayRef[Weather::YR::Model::Pressure]', is => 'ro', lazy_build => 1 );
40             has 'pressure' => ( isa => 'Weather::YR::Model::Pressure', is => 'ro', lazy_build => 1 );
41              
42             # Cloudiness
43             has 'cloudinesses' => ( isa => 'ArrayRef[Weather::YR::Model::Cloudiness]', is => 'ro', lazy_build => 1 );
44             has 'cloudiness' => ( isa => 'Weather::YR::Model::Cloudiness', is => 'ro', lazy_build => 1 );
45              
46             # Fog
47             has 'fogs' => ( isa => 'ArrayRef[Weather::YR::Model::Fog]', is => 'ro', lazy_build => 1 );
48             has 'fog' => ( isa => 'Weather::YR::Model::Fog', is => 'ro', lazy_build => 1 );
49              
50             # Dew point temperature
51             has 'dew_point_temperatures' => ( isa => 'ArrayRef[Weather::YR::Model::DewPointTemperature]', is => 'ro', lazy_build => 1 );
52             has 'dew_point_temperature' => ( isa => 'Weather::YR::Model::DewPointTemperature', is => 'ro', lazy_build => 1 );
53              
54             =head1 METHODS
55              
56             This class inherits all the methods from L<Weather::YR::Day> and provides the
57             following new methods:
58              
59             =cut
60              
61             sub _ok_hour {
62 0     0     my $self = shift;
63 0           my $hour = shift;
64              
65 0 0 0       if ( defined $hour && ($hour >= 12 && $hour <= 15) ) {
      0        
66 0           return 1;
67             }
68             else {
69 0           return 0;
70             }
71             }
72              
73             =head2 temperatures
74              
75             Returns an array reference of all the L<Weather::YR::Model::Temperature>
76             data points for this day.
77              
78             =cut
79              
80             sub _build_temperatures {
81 0     0     my $self = shift;
82              
83 0           return [ map { $_->temperature } @{$self->datapoints} ];
  0            
  0            
84             }
85              
86             =head2 temperature
87              
88             Returns the "most logical" L<Weather::YR::Model::Temperature> data point for
89             this day.
90              
91             This works so that if you are working with "now", it will pick the data point
92             closest to the current time. If you are working with any other days, including
93             "today", it will return the data noon point, or the closest one after noon if
94             there isn't one for noon.
95              
96             =cut
97              
98             sub _build_temperature {
99 0     0     my $self = shift;
100              
101 0           foreach ( @{$self->temperatures} ) {
  0            
102 0 0         if ( $self->_ok_hour($_->from->hour) ) {
103 0           return $_;
104             }
105             }
106              
107 0           return $self->temperatures->[0];
108             }
109              
110             =head2 precipitations
111              
112             Returns an array reference of all the L<Weather::YR::Model::Precipitation>
113             data points for this day.
114              
115             =cut
116              
117             sub _build_precipitations {
118 0     0     my $self = shift;
119              
120 0           my @precips = ();
121              
122 0           foreach ( @{$self->datapoints} ) {
  0            
123 0           foreach ( @{$_->precipitations} ) {
  0            
124 0 0         if ( $_->from->ymd eq $self->date->ymd ) {
125 0           push( @precips, $_ );
126             }
127             }
128             }
129              
130 0           return \@precips;
131             }
132              
133             =head2 precipitation
134              
135             Returns "the most logical" L<Weather::YR::Model::Precipitation> data point
136             for this day.
137              
138             This works so that if you are working with "now", it will pick the data point
139             closest to the current time. If you are working with any other days, including
140             "today", it will return the data noon point, or the closest one after noon if
141             there isn't one for noon.
142              
143             =cut
144              
145             sub _build_precipitation {
146 0     0     my $self = shift;
147              
148 0           foreach ( @{$self->precipitations} ) {
  0            
149 0 0         if ( $self->_ok_hour($_->from->hour) ) {
150 0           return $_;
151             }
152             }
153              
154 0           return $self->precipitations->[0];
155             }
156              
157             =head2 wind_directions
158              
159             Returns an array reference of L<Weather::YR::Model::WindDirection> data points
160             for this day.
161              
162             =cut
163              
164             sub _build_wind_directions {
165 0     0     my $self = shift;
166              
167 0           return [ map { $_->wind_direction } @{$self->datapoints} ];
  0            
  0            
168             }
169              
170             =head2 wind_direction
171              
172             Returns "the most logical" L<Weather::YR::Model::WindDirection> data point
173             for this day.
174              
175             This works so that if you are working with "now", it will pick the data point
176             closest to the current time. If you are working with any other days, including
177             "today", it will return the data noon point, or the closest one after noon if
178             there isn't one for noon.
179              
180             =cut
181              
182             sub _build_wind_direction {
183 0     0     my $self = shift;
184              
185 0           foreach ( @{$self->wind_directions} ) {
  0            
186 0 0         if ( $self->_ok_hour($_->from->hour) ) {
187 0           return $_;
188             }
189             }
190              
191 0           return $self->wind_directions->[0];
192             }
193              
194             =head2 wind_speeds
195              
196             Returns an array reference of L<Weather::YR::Model::WindSpeed> data points
197             for this day.
198              
199             =cut
200              
201             sub _build_wind_speeds {
202 0     0     my $self = shift;
203              
204 0           return [ map { $_->wind_speed } @{$self->datapoints} ];
  0            
  0            
205             }
206              
207             =head2 wind_speed
208              
209             Returns "the most logical" L<Weather::YR::Model::WindSpeed> data point
210             for this day.
211              
212             This works so that if you are working with "now", it will pick the data point
213             closest to the current time. If you are working with any other days, including
214             "today", it will return the data noon point, or the closest one after noon if
215             there isn't one for noon.
216              
217             =cut
218              
219             sub _build_wind_speed {
220 0     0     my $self = shift;
221              
222 0           foreach ( @{$self->wind_speeds} ) {
  0            
223 0 0         if ( $self->_ok_hour($_->from->hour) ) {
224 0           return $_;
225             }
226             }
227              
228 0           return $self->wind_speed->[0];
229             }
230              
231             =head2 humidities
232              
233             Returns an array reference of L<Weather::YR::Model::WindSpeed> data points
234             for this day.
235              
236             =cut
237              
238             sub _build_humidities {
239 0     0     my $self = shift;
240              
241 0           return [ map { $_->humidity } @{$self->datapoints} ];
  0            
  0            
242             }
243              
244             =head2 humidity
245              
246             Returns "the most logical" L<Weather::YR::Model::Humidity> data point
247             for this day.
248              
249             This works so that if you are working with "now", it will pick the data point
250             closest to the current time. If you are working with any other days, including
251             "today", it will return the data noon point, or the closest one after noon if
252             there isn't one for noon.
253              
254             =cut
255              
256             sub _build_humidity {
257 0     0     my $self = shift;
258              
259 0           foreach ( @{$self->humidities} ) {
  0            
260 0 0         if ( $self->_ok_hour($_->from->hour) ) {
261 0           return $_;
262             }
263             }
264              
265 0           return $self->humidities->[0];
266             }
267              
268             =head2 pressures
269              
270             Returns an array reference of L<Weather::YR::Model::Pressure> data points
271             for this day.
272              
273             =cut
274              
275             sub _build_pressures {
276 0     0     my $self = shift;
277              
278 0           return [ map { $_->pressure } @{$self->datapoints} ];
  0            
  0            
279             }
280              
281             =head2 pressure
282              
283             Returns "the most logical" L<Weather::YR::Model::Humidity> data point
284             for this day.
285              
286             This works so that if you are working with "now", it will pick the data point
287             closest to the current time. If you are working with any other days, including
288             "today", it will return the data noon point, or the closest one after noon if
289             there isn't one for noon.
290              
291             =cut
292              
293             sub _build_pressure {
294 0     0     my $self = shift;
295              
296 0           foreach ( @{$self->pressures} ) {
  0            
297 0 0         if ( $self->_ok_hour($_->from->hour) ) {
298 0           return $_;
299             }
300             }
301              
302 0           return $self->pressures->[0];
303             }
304              
305             =head2 cloudinesses
306              
307             Returns an array reference of L<Weather::YR::Model::Cloudiness> data points
308             for this day.
309              
310             =cut
311              
312             sub _build_cloudinesses {
313 0     0     my $self = shift;
314              
315 0           return [ map { $_->cloudiness } @{$self->datapoints} ];
  0            
  0            
316             }
317              
318             =head2 cloudiness
319              
320             Returns "the most logical" L<Weather::YR::Model::Cloudiness> data point
321             for this day.
322              
323             This works so that if you are working with "now", it will pick the data point
324             closest to the current time. If you are working with any other days, including
325             "today", it will return the data noon point, or the closest one after noon if
326             there isn't one for noon.
327              
328             =cut
329              
330             sub _build_cloudiness {
331 0     0     my $self = shift;
332              
333 0           foreach ( @{$self->cloudinesses} ) {
  0            
334 0 0         if ( $self->_ok_hour($_->from->hour) ) {
335 0           return $_;
336             }
337             }
338              
339 0           return $self->cloudinesses->[0];
340             }
341              
342             =head2 fogs
343              
344             Returns an array reference of L<Weather::YR::Model::Fog> data points
345             for this day.
346              
347             =cut
348              
349             sub _build_fogs {
350 0     0     my $self = shift;
351              
352 0           return [ map { $_->fog } @{$self->datapoints} ];
  0            
  0            
353             }
354              
355             =head2 fog
356              
357             Returns "the most logical" L<Weather::YR::Model::Fog> data point
358             for this day.
359              
360             This works so that if you are working with "now", it will pick the data point
361             closest to the current time. If you are working with any other days, including
362             "today", it will return the data noon point, or the closest one after noon if
363             there isn't one for noon.
364              
365             =cut
366              
367             sub _build_fog {
368 0     0     my $self = shift;
369              
370 0           foreach ( @{$self->fogs} ) {
  0            
371 0 0         if ( $self->_ok_hour($_->from->hour) ) {
372 0           return $_;
373             }
374             }
375              
376 0           return $self->fogs->[0];
377             }
378              
379             =head2 dew_point_temperatures
380              
381             Returns an array reference of L<Weather::YR::Model::DewPointTemperature> data points
382             for this day.
383              
384             =cut
385              
386             sub _build_dew_point_temperatures {
387 0     0     my $self = shift;
388              
389 0           return [ map { $_->dew_point_temperature } @{$self->datapoints} ];
  0            
  0            
390             }
391              
392             =head2 dew_point_temperature
393              
394             Returns "the most logical" L<Weather::YR::Model::DewPointTemperature> data point
395             for this day.
396              
397             This works so that if you are working with "now", it will pick the data point
398             closest to the current time. If you are working with any other days, including
399             "today", it will return the data noon point, or the closest one after noon if
400             there isn't one for noon.
401              
402             =cut
403              
404             sub _build_dew_point_temperature {
405 0     0     my $self = shift;
406              
407 0           foreach ( @{$self->dew_point_temperatures} ) {
  0            
408 0 0         if ( $self->_ok_hour($_->from->hour) ) {
409 0           return $_;
410             }
411             }
412              
413 0           return $self->dew_point_temperatures->[0];
414             }
415              
416             #
417             # The End
418             #
419             __PACKAGE__->meta->make_immutable;
420              
421             1;