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.159 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm
trackler-2.2.1.158 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm
trackler-2.2.1.157 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm
trackler-2.2.1.156 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm
trackler-2.2.1.155 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm
trackler-2.2.1.154 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm
trackler-2.2.1.153 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm
trackler-2.2.1.152 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm
trackler-2.2.1.151 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm
trackler-2.2.1.150 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm
trackler-2.2.1.149 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm
trackler-2.2.1.148 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm
trackler-2.2.1.147 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm
trackler-2.2.1.146 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm
trackler-2.2.1.145 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm
trackler-2.2.1.144 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm
trackler-2.2.1.143 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm
trackler-2.2.1.142 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm
trackler-2.2.1.141 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm
trackler-2.2.1.140 tracks/perl5/exercises/clock/.meta/solutions/Clock.pm