From f20f9fca9c5cc255e288a05f55ec64cb952702e3 Mon Sep 17 00:00:00 2001 From: Liam Rosenfeld Date: Sat, 20 Apr 2019 15:01:02 -0400 Subject: [PATCH] Conditional Top Boundary Sides --- Sources/AnimalFarm/Bubble/Bubble.swift | 1 + Sources/AnimalFarm/Bubble/BubbleBuilder.swift | 9 ++++++++- Sources/AnimalFarm/Bubble/Bubbles.swift | 12 ++++++++---- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Sources/AnimalFarm/Bubble/Bubble.swift b/Sources/AnimalFarm/Bubble/Bubble.swift index 25f0bde..c7d74ca 100644 --- a/Sources/AnimalFarm/Bubble/Bubble.swift +++ b/Sources/AnimalFarm/Bubble/Bubble.swift @@ -12,4 +12,5 @@ public struct Bubble { var left: Character var right: Character public var line: String + var topSides: Bool } diff --git a/Sources/AnimalFarm/Bubble/BubbleBuilder.swift b/Sources/AnimalFarm/Bubble/BubbleBuilder.swift index e69fb65..1da7747 100644 --- a/Sources/AnimalFarm/Bubble/BubbleBuilder.swift +++ b/Sources/AnimalFarm/Bubble/BubbleBuilder.swift @@ -12,6 +12,7 @@ internal class BubbleBuilder { let btmChar: Character let leftChar: Character let rightChar: Character + let topSides: Bool // Bubble Dimensions let maxSignWidth = 32 @@ -47,7 +48,12 @@ internal class BubbleBuilder { func buildSignBoundary(length: Int, char: Character) -> String { let dashes = String(repeating: char, count: length) - return "\(leftChar)\(dashes)\(rightChar)" + if topSides { + return "\(leftChar)\(dashes)\(rightChar)" + } else { + return " \(dashes) " + } + } // Line Splitting @@ -100,5 +106,6 @@ internal class BubbleBuilder { self.btmChar = style.btm self.leftChar = style.left self.rightChar = style.right + self.topSides = style.topSides } } diff --git a/Sources/AnimalFarm/Bubble/Bubbles.swift b/Sources/AnimalFarm/Bubble/Bubbles.swift index 2d384c7..d8b8f89 100644 --- a/Sources/AnimalFarm/Bubble/Bubbles.swift +++ b/Sources/AnimalFarm/Bubble/Bubbles.swift @@ -12,21 +12,24 @@ public let bubbles = [ btm: "~", left: "(", right: ")", - line: "0" + line: "0", + topSides: false ), "yell": Bubble( top: "∧", btm: "∨", left: "<", right: ">", - line: "X" + line: "X", + topSides: false ), "sign": Bubble( top: "-", btm: "-", left: "|", right: "|", - line: "" + line: "", + topSides: true ), ] @@ -35,5 +38,6 @@ public let say = Bubble( btm: "-", left: "|", right: "|", - line: "\\" + line: "\\", + topSides: true ) \ No newline at end of file