Skip to content

Commit

Permalink
feat: add URLLorem to support url related LoremKind config
Browse files Browse the repository at this point in the history
  • Loading branch information
EnesKaraosman committed Mar 29, 2024
1 parent af081d4 commit 52ed8df
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 9 deletions.
12 changes: 10 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,20 @@ struct Hotel {

@Lorem(.string(.phoneNumber))
let phoneNumber: String


@Lorem(.url(.website))
let website: URL

let rooms: [Room]

@LoremSwiftify
struct Room {
let id: UUID
let capacity: Capacity

@Lorem(.url(.image))
let image: URL

@LoremSwiftify
enum Capacity: Int {
case one = 1
Expand All @@ -123,7 +129,8 @@ struct Hotel {
public static func lorem() -> Self {
Hotel.Room(
id: .lorem(),
capacity: .lorem()
capacity: .lorem(),
image: .lorem(.url(.image))
)
}
}
Expand All @@ -134,6 +141,7 @@ extension Hotel: LoremIpsumize {
Hotel(
name: .lorem(.string(.name)),
phoneNumber: .lorem(.string(.phoneNumber)),
website: .lorem(.url(.website)),
rooms: .lorem()
)
}
Expand Down
23 changes: 17 additions & 6 deletions Sources/LoremSwiftify/LoremIpsumize+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,17 @@ extension String: LoremIpsumize {
public static func lorem(_ kind: LoremKind?) -> String {
switch kind {
case .string(.name):
return faker.name.name()
faker.name.name()
case .string(.email):
return faker.internet.email()
faker.internet.email()
case .string(.phoneNumber):
return faker.phoneNumber.phoneNumber()
faker.phoneNumber.phoneNumber()
case .string(.creditCard):
return faker.business.creditCardNumber()
faker.business.creditCardNumber()
case .string(.hexColor):
return Color.randomHexColor()
Color.randomHexColor()
default:
return lorem()
lorem()
}
}

Expand Down Expand Up @@ -177,6 +177,17 @@ extension URL: LoremIpsumize {
public static func lorem() -> URL {
URL(string: "https://picsum.photos/300") ?? URL(string: faker.internet.url())!
}

public static func lorem(_ kind: LoremKind?) -> URL {
switch kind {
case .url(.website):
URL(string: faker.internet.url()) ?? lorem()
case .url(.image):
URL(string: "https://picsum.photos/400") ?? lorem()
default:
lorem()
}
}
}

extension Color: LoremIpsumize {
Expand Down
10 changes: 9 additions & 1 deletion Sources/LoremSwiftify/LoremKind.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import Foundation

public enum LoremKind {
case string(StringLorem)
case url(URLLorem)
}

public extension LoremKind {
enum StringLorem: String, RawRepresentable {
enum StringLorem: String {
case name
case email
case phoneNumber
Expand All @@ -21,3 +22,10 @@ public extension LoremKind {
case `default`
}
}

public extension LoremKind {
enum URLLorem: String {
case image
case website
}
}
6 changes: 6 additions & 0 deletions Sources/LoremSwiftifyClient/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,19 @@ struct Hotel {
@Lorem(.string(.phoneNumber))
let phoneNumber: String

@Lorem(.url(.website))
let website: URL

let rooms: [Room]

@LoremSwiftify
struct Room {
let id: UUID
let capacity: Capacity

@Lorem(.url(.image))
let image: URL

@LoremSwiftify
enum Capacity: Int {
case one = 1
Expand Down

0 comments on commit 52ed8df

Please sign in to comment.