Skip to content

Commit 975ab32

Browse files
committed
Remove duplicate code, revert enum to string
1 parent 7915bf7 commit 975ab32

File tree

2 files changed

+24
-49
lines changed

2 files changed

+24
-49
lines changed

WooCommerce/Classes/Model/Order+Woo.swift

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,33 @@ extension Order {
1818
/// Translates a Section Identifier into a Human-Readable String.
1919
///
2020
static func descriptionForSectionIdentifier(_ identifier: String) -> String {
21-
guard let section = Sections(rawValue: identifier) else {
21+
guard let age = Age(rawValue: identifier) else {
2222
return String()
2323
}
2424

25-
return section.description
25+
return age.description
2626
}
27+
}
2728

28-
// MARK: - Private Helpers
29-
fileprivate enum Sections: String {
30-
case Months = "0"
31-
case Weeks = "2"
32-
case Days = "4"
33-
case Yesterday = "5"
34-
case Today = "6"
35-
36-
var description: String {
37-
switch self {
38-
case .Months:
39-
return NSLocalizedString("Older than a Month", comment: "Notifications Months Section Header")
40-
case .Weeks:
41-
return NSLocalizedString("Older than a Week", comment: "Notifications Weeks Section Header")
42-
case .Days:
43-
return NSLocalizedString("Older than 2 days", comment: "Notifications +2 Days Section Header")
44-
case .Yesterday:
45-
return NSLocalizedString("Yesterday", comment: "Notifications Yesterday Section Header")
46-
case .Today:
47-
return NSLocalizedString("Today", comment: "Notifications Today Section Header")
48-
}
29+
enum Age: String {
30+
case months = "0"
31+
case weeks = "2"
32+
case days = "4"
33+
case yesterday = "5"
34+
case today = "6"
35+
36+
var description: String {
37+
switch self {
38+
case .months:
39+
return NSLocalizedString("Older than a Month", comment: "Notifications Months Section Header")
40+
case .weeks:
41+
return NSLocalizedString("Older than a Week", comment: "Notifications Weeks Section Header")
42+
case .days:
43+
return NSLocalizedString("Older than 2 days", comment: "Notifications +2 Days Section Header")
44+
case .yesterday:
45+
return NSLocalizedString("Yesterday", comment: "Notifications Yesterday Section Header")
46+
case .today:
47+
return NSLocalizedString("Today", comment: "Notifications Today Section Header")
4948
}
5049
}
5150
}

WooCommerce/Classes/Model/StorageOrder+Woo.swift

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ extension StorageOrder {
66
/// Returns a Section Identifier that can be sorted. Note that this string is not human readable, and
77
/// you should use the *descriptionForSectionIdentifier* method as well!.
88
///
9-
@objc func normalizedAgeAsString() -> Int {
9+
@objc func normalizedAgeAsString() -> String {
1010
// Normalize Dates: Time must not be considered. Just the raw dates
1111
guard let fromDate = dateCreated?.normalizedDate() else {
12-
return 0
12+
return ""
1313
}
1414

1515
let toDate = Date().normalizedDate()
@@ -37,28 +37,4 @@ extension StorageOrder {
3737

3838
return identifier.rawValue
3939
}
40-
41-
// MARK: - Private Helpers
42-
private enum Age: Int, CustomStringConvertible {
43-
case months = 0
44-
case weeks = 2
45-
case days = 4
46-
case yesterday = 5
47-
case today = 6
48-
49-
var description: String {
50-
switch self {
51-
case .months:
52-
return NSLocalizedString("Older than a Month", comment: "Notifications Months Section Header")
53-
case .weeks:
54-
return NSLocalizedString("Older than a Week", comment: "Notifications Weeks Section Header")
55-
case .days:
56-
return NSLocalizedString("Older than 2 days", comment: "Notifications +2 Days Section Header")
57-
case .yesterday:
58-
return NSLocalizedString("Yesterday", comment: "Notifications Yesterday Section Header")
59-
case .today:
60-
return NSLocalizedString("Today", comment: "Notifications Today Section Header")
61-
}
62-
}
63-
}
6440
}

0 commit comments

Comments
 (0)