Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial model-level work on filters

Read-only so far...
  • Loading branch information...
commit 46244e6cce9d4a77372e038ead29f17657cd1bcb 1 parent 40deb82
Brent Royal-Gordon authored
Showing with 130 additions and 0 deletions.
  1. +66 −0 ANFilter.h
  2. +64 −0 ANFilter.m
View
66 ANFilter.h
@@ -0,0 +1,66 @@
+//
+// ANFilter.h
+// Alef
+//
+// Created by Brent Royal-Gordon on 10/19/12.
+// Copyright (c) 2012 Architechies. All rights reserved.
+//
+
+#import "ANIdentifiedResource.h"
+
+typedef enum {
+ ANFilterMatchPolicyIncludeAny,
+ ANFilterMatchPolicyIncludeAll,
+ ANFilterMatchPolicyExcludeAny,
+ ANFilterMatchPolicyExcludeAll
+} ANFilterMatchPolicy;
+
+extern NSString * ANStringFromFilterMatchPolicy(ANFilterMatchPolicy matchPolicy);
+extern ANFilterMatchPolicy ANFilterMatchPolicyFromString(NSString * string);
+
+@interface ANFilter : ANIdentifiedResource
+
+@property (nonatomic,readonly) NSString * name;
+
+@property (nonatomic,readonly) NSArray * clauses;
+@property (nonatomic,readonly) NSArray * clauseRepresentations;
+
+@property (nonatomic,readonly) ANFilterMatchPolicy matchPolicy;
+@property (nonatomic,readonly) NSString * matchPolicyRepresentation;
+
+@end
+
+typedef enum {
+ ANFilterClauseObjectTypePost,
+ ANFilterClauseObjectTypeStar,
+ ANFilterClauseObjectTypeUserFollow
+} ANFilterClauseObjectType;
+
+extern NSString * ANStringFromFilterClauseObjectType(ANFilterClauseObjectType objectType);
+extern ANFilterClauseObjectType ANFilterClauseObjectTypeFromString(NSString * string);
+
+typedef enum {
+ ANFilterClauseOperatorEquals,
+ ANFilterClauseOperatorMatches,
+ ANFilterClauseOperatorLess,
+ ANFilterClauseOperatorLessOrEqual,
+ ANFilterClauseOperatorGreater,
+ ANFilterClauseOperatorGreaterOrEqual,
+ ANFilterClauseOperatorOneOf
+} ANFilterClauseOperator;
+
+extern NSString * ANStringFromFilterClauseOperator(ANFilterClauseOperator operator);
+extern ANFilterClauseOperator ANFilterClauseOperatorFromString(NSString * string);
+
+@interface ANFilterClause : ANResource
+
+@property (nonatomic,readonly) ANFilterClauseObjectType objectType;
+@property (nonatomic,readonly) NSString * objectTypeRepresentation;
+
+@property (nonatomic,readonly) ANFilterClauseOperator operator;
+@property (nonatomic,readonly) NSString * operatorRepresentation;
+
+@property (nonatomic,readonly) NSString * field;
+@property (nonatomic,readonly) id value;
+
+@end
View
64 ANFilter.m
@@ -0,0 +1,64 @@
+//
+// ANFilter.m
+// Alef
+//
+// Created by Brent Royal-Gordon on 10/19/12.
+// Copyright (c) 2012 Architechies. All rights reserved.
+//
+
+#import "ANFilter.h"
+
+@implementation ANFilter
+
+@dynamic name;
+@dynamic clauseRepresentations;
+@dynamic matchPolicyRepresentation;
+
++ (NSSet*)keyPathsForValuesAffectingClauses {
+ return [NSSet setWithObject:@"clauseRepresentations"];
+}
+
+- (NSArray *)clauses {
+ NSMutableArray * array = [NSMutableArray new];
+
+ for(NSDictionary * rep in self.clauseRepresentations) {
+ [array addObject:[[ANFilterClause alloc] initWithRepresentation:rep session:self.session]];
+ }
+
+ return array;
+}
+
++ (NSSet *)keyPathsForValuesAffectingMatchPolicy {
+ return [NSSet setWithObject:@"matchPolicyRepresentation"];
+}
+
+- (ANFilterMatchPolicy)matchPolicy {
+ return ANFilterMatchPolicyFromString(self.matchPolicyRepresentation);
+}
+
+@end
+
+@implementation ANFilterClause
+
+@dynamic objectTypeRepresentation;
+@dynamic operatorRepresentation;
+@dynamic field;
+@dynamic value;
+
++ (NSSet *)keyPathsForValuesAffectingObjectType {
+ return [NSSet setWithObject:@"objectTypeRepresentation"];
+}
+
+- (ANFilterClauseObjectType)objectType {
+ return ANFilterClauseObjectTypeFromString(self.objectTypeRepresentation);
+}
+
++ (NSSet *)keyPathsForValuesAffectingOperator {
+ return [NSSet setWithObject:@"operatorRepresentation"];
+}
+
+- (ANFilterClauseOperator)operator {
+ return ANFilterClauseOperatorFromString(self.operatorRepresentation);
+}
+
+@end
Please sign in to comment.
Something went wrong with that request. Please try again.