Fehler #12 » Unit.patch
newUnit.pm 2014-11-03 14:26:04.000000000 +0100 | ||
---|---|---|
return $self->{__base_factor};
|
||
}
|
||
sub can_convert_to {
|
||
my ($self, $other_unit) = @_;
|
||
foreach($self->convertible_units)
|
||
{
|
||
my $element = $_;
|
||
foreach(@$element)
|
||
{
|
||
my $subelement = $_;
|
||
if( $subelement->get_base_name() eq $other_unit->get_base_name() )
|
||
{
|
||
return 1;
|
||
}
|
||
}
|
||
}
|
||
return 0;
|
||
}
|
||
sub get_base_name{
|
||
my $self = shift;
|
||
my $tmp = $self;
|
||
while ($tmp->base)
|
||
{
|
||
$tmp = $tmp->base;
|
||
}
|
||
return $tmp->name;
|
||
}
|
||
sub convert_to {
|
||
my ($self, $qty, $other_unit) = @_;
|
||
my $my_base_factor = $self->base_factor || 1;
|
||
my $other_base_factor = $other_unit->base_factor || 1;
|
||
return $qty * $my_base_factor / $other_base_factor;
|
||
|
||
if($self->can_convert_to($other_unit))
|
||
{
|
||
return $qty * $my_base_factor / $other_base_factor;
|
||
}
|
||
else
|
||
{
|
||
return $qty;
|
||
}
|
||
}
|
||
1;
|