| 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::StyrOchStall::Station; | ||||||||||
| 6 | |||||||||||
| 7 | # ABSTRACT: Data on a bike station | ||||||||||
| 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 | 1 | ▶ | use syntax 'qs'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 1 | has_xpath_value id => './x:Id'; | |||||||||
| 15 | 1 | has_xpath_value original_label => './x:Label'; | |||||||||
| 16 | 1 | has_xpath_value lat => './x:Lat'; | |||||||||
| 17 | 1 | has_xpath_value long => './x:Long'; | |||||||||
| 18 | 1 | has_xpath_value _capacity => './x:Capacity'; | |||||||||
| 19 | 1 | has_xpath_value _free_bikes => './x:FreeBikes'; | |||||||||
| 20 | 1 | has_xpath_value _free_stands => './x:FreeStands'; | |||||||||
| 21 | 1 | has_xpath_value state => './x:State'; | |||||||||
| 22 | |||||||||||
| 23 | sub label { | ||||||||||
| 24 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
label: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 25 | |||||||||||
| 26 | 0 | my $label = $self->original_label; | |||||||||
| 27 | 0 | $label =~ s{([\w']+)}{\u\L$1}g; | |||||||||
| 28 | 0 | return $label; | |||||||||
| 29 | } | ||||||||||
| 30 | |||||||||||
| 31 | sub capacity { | ||||||||||
| 32 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
capacity: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 33 | |||||||||||
| 34 | 0 | ▶ | return length $self->_capacity ? $self->_capacity : 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | } | ||||||||||
| 36 | sub free_bikes { | ||||||||||
| 37 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
free_bikes: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 38 | |||||||||||
| 39 | 0 | ▶ | return length $self->_free_bikes ? $self->_free_bikes : 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | } | ||||||||||
| 41 | sub free_stands { | ||||||||||
| 42 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
free_stands: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 43 | |||||||||||
| 44 | 0 | ▶ | return length $self->_free_stands ? $self->_free_stands : 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | } | ||||||||||
| 46 | sub full { | ||||||||||
| 47 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
full: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 48 | |||||||||||
| 49 | 0 | return $self->free_stands == 0; | |||||||||
| 50 | } | ||||||||||
| 51 | sub empty { | ||||||||||
| 52 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
empty: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 53 | |||||||||||
| 54 | 0 | return $self->free_bikes == 0; | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | sub to_text { | ||||||||||
| 58 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
to_text: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 59 | |||||||||||
| 60 | 0 | return sprintf qs{ | |||||||||
| 61 | Id: %s | ||||||||||
| 62 | Label: %s | ||||||||||
| 63 | Latitude: %s | ||||||||||
| 64 | Longitude: %s | ||||||||||
| 65 | Capacity: %2d | ||||||||||
| 66 | Free bikes: %2d | ||||||||||
| 67 | Free stands: %2d | ||||||||||
| 68 | Empty: %s | ||||||||||
| 69 | Full: %s | ||||||||||
| 70 | State: %s | ||||||||||
| 71 | }, | ||||||||||
| 72 | $self->id, | ||||||||||
| 73 | 1 | $self->label, | |||||||||
| 74 | $self->lat, | ||||||||||
| 75 | 1 | $self->long, | |||||||||
| 76 | $self->capacity, | ||||||||||
| 77 | $self->free_bikes, | ||||||||||
| 78 | $self->free_stands, | ||||||||||
| 79 | $self->empty, | ||||||||||
| 80 | $self->full, | ||||||||||
| 81 | $self->state; | ||||||||||
| 82 | } | ||||||||||
| 83 | |||||||||||
| 84 | finalize_class(); | ||||||||||
| 85 | |||||||||||
| 86 | 1; | ||||||||||
| 87 | |||||||||||
| 88 | __END__ | ||||||||||
| 89 | |||||||||||
| 90 | =pod | ||||||||||
| 91 | |||||||||||
| 92 | =encoding utf-8 | ||||||||||
| 93 | |||||||||||
| 94 | =head1 NAME | ||||||||||
| 95 | |||||||||||
| 96 | OpenGbg::Service::StyrOchStall::Station - Data on a bike station | ||||||||||
| 97 | |||||||||||
| 98 | =head1 VERSION | ||||||||||
| 99 | |||||||||||
| 100 | Version 0.1401, released 2016-05-05. | ||||||||||
| 101 | |||||||||||
| 102 | =head1 SYNOPSIS | ||||||||||
| 103 | |||||||||||
| 104 | my $service = OpenGbg->new->styr_och_stall; | ||||||||||
| 105 | my $station = $service->get_bike_stations->get_by_index(2); | ||||||||||
| 106 | |||||||||||
| 107 | printf 'Free bikes: %d', $station->free_bikes; | ||||||||||
| 108 | |||||||||||
| 109 | =head1 ATTRIBUTES | ||||||||||
| 110 | |||||||||||
| 111 | =head2 id | ||||||||||
| 112 | |||||||||||
| 113 | Integer. The station id. | ||||||||||
| 114 | |||||||||||
| 115 | =head2 label | ||||||||||
| 116 | |||||||||||
| 117 | String. The station/location name. | ||||||||||
| 118 | |||||||||||
| 119 | =head2 lat | ||||||||||
| 120 | |||||||||||
| 121 | =head2 long | ||||||||||
| 122 | |||||||||||
| 123 | Decimal degrees. The location of the station. | ||||||||||
| 124 | |||||||||||
| 125 | =head2 capacity | ||||||||||
| 126 | |||||||||||
| 127 | Integer. Maximum number of bikes. | ||||||||||
| 128 | |||||||||||
| 129 | =head2 free_bikes | ||||||||||
| 130 | |||||||||||
| 131 | Integer. Number of available bikes. | ||||||||||
| 132 | |||||||||||
| 133 | =head2 free_stands | ||||||||||
| 134 | |||||||||||
| 135 | Integer. Number of open stands. | ||||||||||
| 136 | |||||||||||
| 137 | =head2 state | ||||||||||
| 138 | |||||||||||
| 139 | String. Can be C<open>, C<closed>, C<maintenance> or C<construction>. | ||||||||||
| 140 | |||||||||||
| 141 | =head2 empty | ||||||||||
| 142 | |||||||||||
| 143 | Boolean. Returns true if there is no bike available. | ||||||||||
| 144 | |||||||||||
| 145 | =head2 full | ||||||||||
| 146 | |||||||||||
| 147 | Boolean. Returns true if there is no room to return a bike to. | ||||||||||
| 148 | |||||||||||
| 149 | =head1 METHODS | ||||||||||
| 150 | |||||||||||
| 151 | =head2 to_text() | ||||||||||
| 152 | |||||||||||
| 153 | Returns a string with the station data in a table. | ||||||||||
| 154 | |||||||||||
| 155 | =head1 SOURCE | ||||||||||
| 156 | |||||||||||
| 157 | L<https://github.com/Csson/p5-OpenGbg> | ||||||||||
| 158 | |||||||||||
| 159 | =head1 HOMEPAGE | ||||||||||
| 160 | |||||||||||
| 161 | L<https://metacpan.org/release/OpenGbg> | ||||||||||
| 162 | |||||||||||
| 163 | =head1 AUTHOR | ||||||||||
| 164 | |||||||||||
| 165 | Erik Carlsson <info@code301.com> | ||||||||||
| 166 | |||||||||||
| 167 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 168 | |||||||||||
| 169 | This software is copyright (c) 2016 by Erik Carlsson. | ||||||||||
| 170 | |||||||||||
| 171 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 172 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 173 | |||||||||||
| 174 | =cut | ||||||||||