OpenGbg/Service/AirQuality/Measurements.pm

filter: Statementstmt 100% 16 / 16 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 100% 20 / 20 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« OpenGbg/Service/AirQuality/GetMeasurements.pm ↑ Summary OpenGbg/Service/Bridge/BridgeOpenings.pm »
1 1 ▶use 5.10.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package OpenGbg::Service::AirQuality::Measurements;
6  
7 # ABSTRACT: A list of air quality measurements
8 1 our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY
9 1 our $VERSION = '0.1401';
10  
11 1 ▶use XML::Rabbit;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 has_xpath_object_list _measurements => './x:Measurement' => 'OpenGbg::Service::AirQuality::Measurement',
14 handles => {
15 all => 'elements',
16 count => 'count',
17 filter => 'grep',
18 find => 'first',
19 get_by_index => 'get',
20 map => 'map',
21 sort => 'sort',
22 };
23  
24 1 finalize_class();
25  
26 1 1;
27  
28 __END__
29  
30 =pod
31  
32 =encoding utf-8
33  
34 =head1 NAME
35  
36 OpenGbg::Service::AirQuality::Measurements - A list of air quality measurements
37  
38 =head1 VERSION
39  
40 Version 0.1401, released 2016-05-05.
41  
42 =head1 SYNOPSIS
43  
44 my $service = OpenGbg->new->air_quality;
45 my $response = $service->get_measurements(start => '2014-10-15', end => '2014-10-25');
46  
47 print $response->measurements->get_by_index(3)->to_text;
48  
49 =head1 METHODS
50  
51 =head2 all
52  
53 Returns an array of the L<OpenGbg::Service::AirQuality::Measurement> objects in the response.
54  
55 =head2 count
56  
57 Returns the number of L<Measurement|OpenGbg::Service::AirQuality::Measurement> objects in the response.
58  
59 =head2 filter(sub { ... })
60  
61 Allows filtering of the measurements. Takes a sub routine reference, into which all L<Measurement|OpenGbg::Service::AirQuality::Measurement> objects are
62 passed one-by-one into C<$_>. Works like C<grep>.
63  
64 =head2 find(sub { ... })
65  
66 Just like C<filter>, except it returns the first measurement that matches.
67  
68 =head2 get_by_index($index)
69  
70 Returns the n:th L<Measurement|OpenGbg::Service::AirQuality::Measurement> object in the response.
71  
72 =head2 map(sub { ... })
73  
74 Like C<filter> it takes a sub routine reference and passes each L<Measurement|OpenGbg::Service::AirQuality::Measurement> as C<$_>.
75 Eg, to get the total solar insolation:
76  
77 use List::AllUtils 'sum';
78 my $total_solar_insolation_per_m2 = sum $response->measurements->map( sub { $_->solar_insolation });
79  
80 =head2 sort(sub { ... })
81  
82 Like C<filter> it takes a sub routine reference. It works just like C<sort> except the two L<Measurement|OpenGbg::Service::AirQuality::Measurement> objects to compare are passed as C<$_[0]> and C<$_[1]>
83  
84 my @hottest_hours_first = $response->measurements->sort( sub { $_[1]->temperature <=> $_[0]->temperature });
85  
86 =head1 SOURCE
87  
88 L<https://github.com/Csson/p5-OpenGbg>
89  
90 =head1 HOMEPAGE
91  
92 L<https://metacpan.org/release/OpenGbg>
93  
94 =head1 AUTHOR
95  
96 Erik Carlsson <info@code301.com>
97  
98 =head1 COPYRIGHT AND LICENSE
99  
100 This software is copyright (c) 2016 by Erik Carlsson.
101  
102 This is free software; you can redistribute it and/or modify it under
103 the same terms as the Perl 5 programming language system itself.
104  
105 =cut
« OpenGbg/Service/AirQuality/GetMeasurements.pm ↑ Summary OpenGbg/Service/Bridge/BridgeOpenings.pm »