Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Merge pull request #2 from g-Off/value-public-init
Browse files Browse the repository at this point in the history
makes initializers for Value public
  • Loading branch information
g-Off authored Sep 26, 2019
2 parents 88d47cc + 7d7cc1d commit 7c77191
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions Sources/Liquid/Value/Value.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,49 +21,49 @@ public final class Value: Equatable, Comparable {

fileprivate var storage: Storage

init() {
public init() {
self.storage = .nil
}

fileprivate init(storage: Storage) {
self.storage = storage
}

convenience init(_ value: Bool) {
public convenience init(_ value: Bool) {
self.init(storage: .bool(value))
}

convenience init(_ value: String) {
public convenience init(_ value: String) {
self.init(storage: .string(value))
}

convenience init(_ value: Int) {
public convenience init(_ value: Int) {
self.init(storage: .int(value))
}

convenience init(_ value: Double) {
public convenience init(_ value: Double) {
self.init(storage: .decimal(Decimal(value)))
}

convenience init(_ value: Decimal) {
public convenience init(_ value: Decimal) {
self.init(storage: .decimal(value))
}

convenience init(_ value: [Value]) {
public convenience init(_ value: [Value]) {
self.init(storage: .array(value))
}

convenience init(_ value: [String: Value]) {
public convenience init(_ value: [String: Value]) {
self.init(storage: .dictionary(value))
}

convenience init(_ value: Drop) {
public convenience init(_ value: Drop) {
self.init(storage: .drop(value))
}

// MARK: -

var isTruthy: Bool {
public var isTruthy: Bool {
switch storage {
case .nil, .bool(false):
return false
Expand All @@ -72,7 +72,7 @@ public final class Value: Equatable, Comparable {
}
}

var size: Int {
public var size: Int {
switch storage {
case .array(let value):
return value.count
Expand Down Expand Up @@ -102,49 +102,49 @@ public final class Value: Equatable, Comparable {

// MARK: - Type check conveniences

var isNil: Bool {
public var isNil: Bool {
if case .nil = storage {
return true
}
return false
}

var isInteger: Bool {
public var isInteger: Bool {
if case .int = storage {
return true
}
return false
}

var isDecimal: Bool {
public var isDecimal: Bool {
if case .decimal = storage {
return true
}
return false
}

var isString: Bool {
public var isString: Bool {
if case .string = storage {
return true
}
return false
}

var isArray: Bool {
public var isArray: Bool {
if case .array = storage {
return true
}
return false
}

var isDictionary: Bool {
public var isDictionary: Bool {
if case .dictionary = storage {
return true
}
return false
}

var isDrop: Bool {
public var isDrop: Bool {
if case .drop = storage {
return true
}
Expand All @@ -153,7 +153,7 @@ public final class Value: Equatable, Comparable {

// MARK: - Type conversions

func toInteger() -> Int {
public func toInteger() -> Int {
switch storage {
case .int(let value):
return value
Expand All @@ -164,7 +164,7 @@ public final class Value: Equatable, Comparable {
}
}

func toDecimal() -> Decimal {
public func toDecimal() -> Decimal {
switch storage {
case .int(let value):
return Decimal(value)
Expand All @@ -175,21 +175,21 @@ public final class Value: Equatable, Comparable {
}
}

func toArray() -> [Value] {
public func toArray() -> [Value] {
if case let .array(value) = storage {
return value
}
return []
}

func toDictionary() -> [String: Value] {
public func toDictionary() -> [String: Value] {
if case let .dictionary(value) = storage {
return value
}
return [:]
}

func toString() -> String {
public func toString() -> String {
switch storage {
case .bool(let value):
return "\(value ? "true" : "false")"
Expand All @@ -204,7 +204,7 @@ public final class Value: Equatable, Comparable {
}
}

func toDrop() -> Drop? {
public func toDrop() -> Drop? {
if case let .drop(drop) = storage {
return drop
}
Expand All @@ -213,7 +213,7 @@ public final class Value: Equatable, Comparable {

// MARK: -

func liquidString(encoder: Encoder) -> String {
public func liquidString(encoder: Encoder) -> String {
switch storage {
case .bool(let value):
return "\(value ? "true" : "false")"
Expand All @@ -230,7 +230,7 @@ public final class Value: Equatable, Comparable {

// MARK: - Array manipulation

func push(value: Value) {
public func push(value: Value) {
guard case var .array(array) = storage else {
return
}
Expand All @@ -239,7 +239,7 @@ public final class Value: Equatable, Comparable {
}

@discardableResult
func pop() -> Value? {
public func pop() -> Value? {
guard case var .array(array) = storage else {
return nil
}
Expand All @@ -250,7 +250,7 @@ public final class Value: Equatable, Comparable {

// MARK: - Dictionary manipulation

subscript(at: String) -> Value? {
public subscript(at: String) -> Value? {
get {
guard case let .dictionary(dictionary) = storage else {
return nil
Expand Down

0 comments on commit 7c77191

Please sign in to comment.