Skip to content

Commit

Permalink
Clean up redundant extension functions, remove unused enums
Browse files Browse the repository at this point in the history
  • Loading branch information
itsmattking committed Jul 29, 2024
1 parent 202635d commit 0f0f3a4
Show file tree
Hide file tree
Showing 18 changed files with 9 additions and 68 deletions.
32 changes: 1 addition & 31 deletions src/main/kotlin/info/mking/k2zpl/builder/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,9 @@

package info.mking.k2zpl.builder

import info.mking.k2zpl.command.ZplCommand
import info.mking.k2zpl.command.options.ZplFont
import info.mking.k2zpl.command.options.ZplYesNo

/**
* Shortcut for addCommand
*/
fun ZplBuilder.command(command: ZplCommand) {
addCommand(command)
}

/**
* Shortcut for addCommand for string
*/
fun ZplBuilder.command(command: String) {
addCommand(command)
}

/**
* Shortcut for addField
*/
fun ZplBuilder.field(x: Int = 0, y: Int = 0, data: String) {
addField(x, y, data)
}

/**
* Shortcut for addField with font attributes
*/
fun ZplBuilder.field(x: Int, y: Int, font: ZplFont, fontHeight: Int, fontWidth: Int, data: String) {
addField(x, y, font, fontHeight, fontWidth, data)
}

internal fun Boolean.toZplYesNo(): ZplYesNo = when(this) {
internal fun Boolean.toZplYesNo(): ZplYesNo = when (this) {
true -> ZplYesNo.YES
else -> ZplYesNo.NO
}
10 changes: 5 additions & 5 deletions src/main/kotlin/info/mking/k2zpl/builder/ZplBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ class ZplBuilder {
_zplDpiSetting = value
}

fun addCommand(command: ZplCommand) {
fun command(command: ZplCommand) {
commands.add(command)
}

fun addCommand(commandString: String) {
addCommand(CustomCommand(commandString))
fun command(commandString: String) {
command(CustomCommand(commandString))
}

fun build() = buildString {
Expand Down Expand Up @@ -91,7 +91,7 @@ class ZplBuilder {
/**
* Adds a field with specified font and size.
*/
fun addField(x: Int, y: Int, font: ZplFont, fontHeight: Int, fontWidth: Int, data: String) {
fun field(x: Int, y: Int, font: ZplFont, fontHeight: Int, fontWidth: Int, data: String) {
fieldOrigin(x, y)
font(font, defaultFont.orientation, fontHeight, fontWidth)
fieldData(data)
Expand All @@ -101,7 +101,7 @@ class ZplBuilder {
/**
* Adds a field with the default font.
*/
fun addField(x: Int = 0, y: Int = 0, data: String) {
fun field(x: Int = 0, y: Int = 0, data: String) {
fieldOrigin(x, y)
font(defaultFont.font, defaultFont.orientation, defaultFont.height, defaultFont.width)
fieldData(data)
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/info/mking/k2zpl/command/BarCode.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package info.mking.k2zpl.command

import info.mking.k2zpl.builder.ZplBuilder
import info.mking.k2zpl.builder.command
import info.mking.k2zpl.builder.toZplYesNo
import info.mking.k2zpl.command.options.ZplBarcodeType
import info.mking.k2zpl.command.options.ZplFieldOrientation
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/info/mking/k2zpl/command/EndFormat.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package info.mking.k2zpl.command

import info.mking.k2zpl.builder.ZplBuilder
import info.mking.k2zpl.builder.command

internal data object EndFormat : ZplCommand {
override val command: CharSequence = "^XZ"
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/info/mking/k2zpl/command/FieldBlock.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package info.mking.k2zpl.command

import info.mking.k2zpl.builder.ZplBuilder
import info.mking.k2zpl.builder.command
import info.mking.k2zpl.command.options.ZplTextAlignment

internal data class FieldBlock(
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/info/mking/k2zpl/command/FieldData.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package info.mking.k2zpl.command

import info.mking.k2zpl.builder.ZplBuilder
import info.mking.k2zpl.builder.command

internal data class FieldData(val data: String) : ZplCommand {
override val command: CharSequence = "^FD"
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/info/mking/k2zpl/command/FieldOrigin.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package info.mking.k2zpl.command

import info.mking.k2zpl.builder.ZplBuilder
import info.mking.k2zpl.builder.command
import info.mking.k2zpl.command.options.ZplJustification

internal data class FieldOrigin(
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/info/mking/k2zpl/command/FieldSeparator.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package info.mking.k2zpl.command

import info.mking.k2zpl.builder.ZplBuilder
import info.mking.k2zpl.builder.command

internal data object FieldSeparator : ZplCommand {
override val command: CharSequence = "^FS"
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/info/mking/k2zpl/command/Font.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package info.mking.k2zpl.command

import info.mking.k2zpl.builder.ZplBuilder
import info.mking.k2zpl.builder.command
import info.mking.k2zpl.command.options.ZplFieldOrientation
import info.mking.k2zpl.command.options.ZplFont

Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/info/mking/k2zpl/command/GraphicBox.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package info.mking.k2zpl.command

import info.mking.k2zpl.builder.ZplBuilder
import info.mking.k2zpl.builder.command
import info.mking.k2zpl.command.options.ZplLineColor

internal data class GraphicBox(
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/info/mking/k2zpl/command/GraphicField.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package info.mking.k2zpl.command

import info.mking.k2zpl.builder.ZplBuilder
import info.mking.k2zpl.builder.command
import info.mking.k2zpl.command.options.ZplCompressionType

internal data class GraphicField(
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/info/mking/k2zpl/command/LabelHome.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package info.mking.k2zpl.command

import info.mking.k2zpl.builder.ZplBuilder
import info.mking.k2zpl.builder.command

internal data class LabelHome(val x: Int, val y: Int) : ZplCommand {
override val command: CharSequence = "^LH"
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/info/mking/k2zpl/command/LabelLength.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package info.mking.k2zpl.command

import info.mking.k2zpl.builder.ZplBuilder
import info.mking.k2zpl.builder.command

internal data class LabelLength(val length: Int) : ZplCommand {
init {
Expand Down
3 changes: 1 addition & 2 deletions src/main/kotlin/info/mking/k2zpl/command/MediaMode.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package info.mking.k2zpl.command

import info.mking.k2zpl.builder.ZplBuilder
import info.mking.k2zpl.builder.command
import info.mking.k2zpl.builder.toZplYesNo
import info.mking.k2zpl.command.options.ZplMediaMode
import info.mking.k2zpl.command.options.ZplYesNo
Expand All @@ -12,7 +11,7 @@ internal data class MediaMode(
) : ZplCommand {
override val command: CharSequence = "^MM"
override val parameters: LinkedHashMap<CharSequence, Any?> =
linkedMapOf("m" to mediaMode.value, "p" to prePeelSelect)
linkedMapOf("m" to mediaMode, "p" to prePeelSelect)
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/info/mking/k2zpl/command/PrintWidth.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package info.mking.k2zpl.command

import info.mking.k2zpl.builder.ZplBuilder
import info.mking.k2zpl.builder.command

internal data class PrintWidth(val width: Int) : ZplCommand {
init {
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/info/mking/k2zpl/command/StartFormat.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package info.mking.k2zpl.command

import info.mking.k2zpl.builder.ZplBuilder
import info.mking.k2zpl.builder.command

internal data object StartFormat : ZplCommand {
override val command: CharSequence = "^XA"
Expand Down
15 changes: 0 additions & 15 deletions src/main/kotlin/info/mking/k2zpl/command/options/ZplPrintSpeed.kt

This file was deleted.

4 changes: 2 additions & 2 deletions src/test/kotlin/info/mking/k2zpl/builder/ZplBuilderTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ class ZplBuilderTest : DescribeSpec({

describe("addCommand") {
it("should call build on the passed command") {
subject.addCommand(mockZplCommand)
subject.command(mockZplCommand)
subject.build()
verify { mockZplCommand.build(ofType()) }
}
it("should used the pass string command") {
subject.addCommand("another-command")
subject.command("another-command")
subject.build() shouldBe "another-command\n"
}
}
Expand Down

0 comments on commit 0f0f3a4

Please sign in to comment.