Skip to content

Commit

Permalink
add Package and Sources
Browse files Browse the repository at this point in the history
  • Loading branch information
marklin2012 committed Apr 19, 2016
1 parent d891a84 commit d7c513d
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import PackageDescription

let package = Package(
name: "O2PlayingCard"
)
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# O2PlayingCard
28 changes: 28 additions & 0 deletions Sources/O2PlayingCard.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
public struct O2PlayingCard {
let rank: O2Rank
let suit: O2Suit
}


// MARK: - Equatable

extension O2PlayingCard: Equatable {}

public func ==(lhs:O2PlayingCard, rhs: O2PlayingCard) -> Bool {
return lhs.rank == rhs.rank && lhs.suit == rhs.suit
}

// MARK: - Comparable
extension O2PlayingCard: Comparable {}

public func <(lhs: O2PlayingCard, rhs: O2PlayingCard) -> Bool {
return lhs.suit < rhs.suit || (lhs.suit == rhs.suit && lhs.rank < rhs.rank)
}

// MARK: - CustomStringConvertible

extension O2PlayingCard: CustomStringConvertible {
public var description: String {
return "\(suit)\(rank)"
}
}
40 changes: 40 additions & 0 deletions Sources/O2Rank.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
public enum O2Rank: Int {
case Ace = 1
case Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten
case Jack, Queen, King
}

// MARK: - Comparable

extension O2Rank: Comparable {}

public func <(lhs: O2Rank, rhs: O2Rank) -> Bool {
switch (lhs,rhs) {
case (_, _) where lhs == rhs:
return false
case (.Ace, _):
return false
default:
return lhs.rawValue < rhs.rawValue
}
}

// MARK: - CustomStringConvertible

extension O2Rank: CustomStringConvertible {
public var description: String {
switch self {
case .Ace:
return "A"
case .Jack:
return "J"
case .Queen:
return "Q"
case .King:
return "K"
default:
return "\(rawValue)"
}
}
}

35 changes: 35 additions & 0 deletions Sources/O2Suit.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
public enum O2Suit: String {
case Spades, Hearts, Diamonds, Clubs
}

// MARK: - Comparable

extension O2Suit: Comparable {}

public func<(lhs: O2Suit, rhs: O2Suit) -> Bool {
switch (lhs, rhs) {
case (_, _) where lhs == rhs:
return false
case (.Spades, _), (.Hearts, .Diamonds), (.Hearts, .Clubs), (.Diamonds, .Clubs):
return false
default:
return true
}
}


// MARK: - CustomStringConvertible
extension O2Suit: CustomStringConvertible {
public var description: String {
switch self {
case .Spades:
return "♠︎"
case .Hearts:
return ""
case .Diamonds:
return ""
case .Clubs:
return "♣︎"
}
}
}

0 comments on commit d7c513d

Please sign in to comment.