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.139 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm
trackler-2.2.1.138 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm
trackler-2.2.1.137 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm
trackler-2.2.1.136 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm
trackler-2.2.1.135 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm
trackler-2.2.1.134 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm
trackler-2.2.1.133 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm
trackler-2.2.1.132 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm