52 lines
950 B
Objective-C
52 lines
950 B
Objective-C
//
|
|
// MPParsedSummand.m
|
|
// MathPad
|
|
//
|
|
// Created by Kim Wittenburg on 10.09.14.
|
|
// Copyright (c) 2014 Kim Wittenburg. All rights reserved.
|
|
//
|
|
|
|
#import "MPParsedProduct.h"
|
|
|
|
@implementation MPParsedProduct {
|
|
NSMutableArray *_factors;
|
|
}
|
|
|
|
- (instancetype)init
|
|
{
|
|
self = [super init];
|
|
if (self) {
|
|
_factors = [[NSMutableArray alloc] init];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (NSArray *)factors
|
|
{
|
|
return _factors;
|
|
}
|
|
|
|
- (void)addFactor:(MPParsedFactor *)factor
|
|
{
|
|
[_factors addObject:factor];
|
|
}
|
|
|
|
- (NSDecimalNumber *)value
|
|
{
|
|
if (_factors.count == 0) {
|
|
return [NSDecimalNumber zero];
|
|
}
|
|
NSDecimalNumber *value = [NSDecimalNumber one];
|
|
for (MPParsedFactor *factor in _factors) {
|
|
value = [value decimalNumberByMultiplyingBy:factor.value];
|
|
}
|
|
return value;
|
|
}
|
|
|
|
- (NSString *)description
|
|
{
|
|
return [NSString stringWithFormat:@"MPParsedProduct<%@>", [_factors componentsJoinedByString:@"*"]];
|
|
}
|
|
|
|
@end
|