-
Notifications
You must be signed in to change notification settings - Fork 0
/
Business.m
72 lines (56 loc) · 2.18 KB
/
Business.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//
// Business.m
// Yelp
//
// Created by WeiSheng Su on 1/29/15.
// Copyright (c) 2015 codepath. All rights reserved.
//
#import "Business.h"
@implementation Business
- (id)initWithDictionary:(NSDictionary *)dictionary{
self = [super init];
if (self){
self.name = dictionary[@"name"];
self.imageUrl = dictionary[@"image_url"];
self.ratingImageUrl = dictionary[@"rating_img_url"];
self.numReviews = [dictionary[@"review_count"] integerValue];
float milesPerMeter = 0.000621371;
self.distance = [dictionary[@"distance"] integerValue] * milesPerMeter;
NSString *neighborhood = [dictionary valueForKeyPath:@"location.neighborhoods"][0];
NSArray *streetArray = [dictionary valueForKeyPath:@"location.address"];
NSString *street;
if(streetArray.count>0){
street = streetArray[0];
}else{
street = @"";
}
if(neighborhood == nil){
neighborhood = @"";
}
self.address = [NSString stringWithFormat:@"%@ %@",street,neighborhood];
NSArray *categories =dictionary[@"categories"];
NSMutableArray *categoryNames = [NSMutableArray array];
[categories enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
[categoryNames addObject:obj[0]];
}];
self.categories = [categoryNames componentsJoinedByString:@", "];
// NSLog(@"name:%@ \nimageUrl:%@ \nratingImageUrl:%@ \n:numReviews:%ld \ndistance:%.3f \naddress:%@ \ncategories:%@",
// self.name,
// self.imageUrl,
// self.ratingImageUrl,
// self.numReviews,
// self.distance,
// self.address,
// self.categories);
}
return self;
}
+ (NSArray *) businessesWithDictionaries:(NSArray *)dictionaries{
NSMutableArray *businesses =[NSMutableArray array];
for(NSDictionary *dictionary in dictionaries){
Business *business = [[Business alloc] initWithDictionary:dictionary ];
[businesses addObject:business];
}
return businesses;
}
@end