Sha256: bda77d67a548de3714db0511c09f64bd0b378236a2ef9948e07cdd9eab4ec6e8

Contents?: true

Size: 682 Bytes

Versions: 48

Compression:

Stored size: 682 Bytes

Contents

package Clock 2;
use strict;
use warnings;

use POSIX;

sub new {
  my ($class, $attributes) = @_;
  my $self = {
    hour   => $attributes->{hour} || 0,
    minute => $attributes->{minute} || 0,
  };
  return bless($self, $class)->BUILD;
}

sub time {
  my ($self) = @_;
  return sprintf '%02d:%02d', $self->{hour}, $self->{minute};
}

sub add_minutes {
  my ($self, $amount) = @_;
  $self->{minute} += $amount;
  return $self->BUILD;
}

sub subtract_minutes {
  my ($self, $amount) = @_;
  return $self->add_minutes(-$amount);
}

sub BUILD {
  my ($self) = @_;
  $self->{hour} = ( $self->{hour} + floor($self->{minute} / 60) ) % 24;
  $self->{minute} %= 60;
  return $self;
}

1;

Version data entries

48 entries across 48 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm
trackler-2.2.1.179 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm
trackler-2.2.1.178 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm
trackler-2.2.1.177 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm
trackler-2.2.1.176 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm
trackler-2.2.1.175 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm
trackler-2.2.1.174 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm
trackler-2.2.1.173 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm
trackler-2.2.1.172 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm
trackler-2.2.1.171 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm
trackler-2.2.1.170 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm
trackler-2.2.1.169 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm
trackler-2.2.1.167 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm
trackler-2.2.1.166 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm
trackler-2.2.1.165 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm
trackler-2.2.1.164 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm
trackler-2.2.1.163 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm
trackler-2.2.1.162 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm
trackler-2.2.1.161 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm
trackler-2.2.1.160 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm