-
Notifications
You must be signed in to change notification settings - Fork 42
/
FluentQuery.JSON.MethodFactories.pas
82 lines (70 loc) · 2.65 KB
/
FluentQuery.JSON.MethodFactories.pas
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
73
74
75
76
77
78
79
80
81
{****************************************************}
{ }
{ FluentQuery }
{ }
{ Copyright (C) 2013 Malcolm Groves }
{ }
{ http://www.malcolmgroves.com }
{ }
{****************************************************}
{ }
{ This Source Code Form is subject to the terms of }
{ the Mozilla Public License, v. 2.0. If a copy of }
{ the MPL was not distributed with this file, You }
{ can obtain one at }
{ }
{ http://mozilla.org/MPL/2.0/ }
{ }
{****************************************************}
unit FluentQuery.JSON.MethodFactories;
interface
uses
FluentQuery.Core.MethodFactories, System.SysUtils, System.JSON;
type
TJSONPairMethodFactory = class(TMethodFactory<TJSONPair>)
public
// predicates
class function NameMatchesPredicate(Predicate : TPredicate<string>) : TPredicate<TJSONPair>;
class function IsNamed(const Name : string): TPredicate<TJSONPair>;
class function ValueIs<T : class> : TPredicate<TJSonPair>;
end;
TJSONValueMethodFactory = class(TMethodFactory<TJSONValue>)
public
// predicates
class function ValueIs<T : class> : TPredicate<TJSonValue>;
end;
implementation
uses
FluentQuery.Strings.MethodFactories;
{ TJSONPairMethodFactory }
class function TJSONPairMethodFactory.IsNamed(
const Name: string): TPredicate<TJSONPair>;
begin
Result := NameMatchesPredicate(TStringMethodFactory.Matches(Name, True));
end;
class function TJSONPairMethodFactory.NameMatchesPredicate(
Predicate: TPredicate<string>): TPredicate<TJSONPair>;
begin
Result := function (Pair : TJsonPair) : Boolean
begin
Result := Predicate(Pair.JsonString.Value);
end;
end;
class function TJSONPairMethodFactory.ValueIs<T>: TPredicate<TJSonPair>;
begin
Result := function (Pair : TJsonPair) : Boolean
var
LValue : T;
begin
Result := Pair.JsonValue.ClassType = T;
end;
end;
{ TJSONValueMethodFactory }
class function TJSONValueMethodFactory.ValueIs<T>: TPredicate<TJSonValue>;
begin
Result := function (Value : TJsonValue) : Boolean
begin
Result := Value.ClassType = T;
end;
end;
end.