-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgiphy_rating.dart
64 lines (56 loc) · 1.53 KB
/
giphy_rating.dart
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
/// An enumeration for different Giphy rating types.
enum GiphyRating {
/// General audience.
g,
/// Parental guidance.
pg,
/// Parents strongly cautioned.
pg13,
/// Restricted.
r,
/// Not yet rated.
unrated,
/// Suitable for young audience.
y,
/// Explicit content, not safe for work.
nsfw,
}
/// Extension methods for [GiphyRating] to convert from and to string values.
extension GiphyRatingExtension on GiphyRating {
/// Converts a string value to a corresponding [GiphyRating] enum value.
///
/// Throws an [ArgumentError] if the given string does not match any [GiphyRating] values.
///
/// [value] The string representation of the Giphy rating.
///
/// Returns the matching [GiphyRating] value.
static GiphyRating fromStringValue(String value) {
switch (value) {
case 'r':
return GiphyRating.r;
case 'y':
return GiphyRating.y;
case 'g':
return GiphyRating.g;
case 'pg':
return GiphyRating.pg;
case 'pg13':
return GiphyRating.pg13;
case 'unrated':
return GiphyRating.unrated;
case 'nsfw':
return GiphyRating.nsfw;
default:
throw ArgumentError('Invalid rating type: $value');
}
}
/// Converts a GiphyRating enum value to its corresponding string representation.
///
/// Example:
/// ```dart
/// String value = GiphyRatingExtension.toStringValue(GiphyRating.pg13);
/// ```
static String toStringValue(GiphyRating rating) {
return rating.toString().split('.').last;
}
}