Skip to content

Commit

Permalink
[#13] Add MediaType ^MT command (#26)
Browse files Browse the repository at this point in the history
* [#13] Add MediaType `^MT` command

- Adds `MediaType` with extension function `mediaType`

* Suppress unused `ZplMediaType`

* Fix `MediaTypeTest` nesting
  • Loading branch information
itsmattking authored Oct 31, 2024
1 parent 39af7d8 commit 05e8503
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/main/kotlin/com/sainsburys/k2zpl/command/MediaType.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.sainsburys.k2zpl.command

import com.sainsburys.k2zpl.builder.ZplBuilder
import com.sainsburys.k2zpl.command.options.ZplMediaType

internal data class MediaType(
val type: ZplMediaType,
) : ZplCommand {
override val command = "^MT"
override val parameters: ZplParameters = zplParameters(
"t" to type
)
}

/**
* Sets the media type for the label.
* Allows to set thermal vs. ribbon.
*
* The ^MT command selects the type of media being used in the printer.
*
* @param type The media type of the printer.
*
* [ZplMediaType.THERMAL_TRANSFER] – this media uses a high-carbon black or colored ribbon. The ink on the ribbon is bonded to the media.
*
* [ZplMediaType.DIRECT_TRANSFER] – this media is heat sensitive and requires no ribbon.
*
*/
fun ZplBuilder.mediaType(type: ZplMediaType) {
command(MediaType(type))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@file:Suppress("UNUSED")

package com.sainsburys.k2zpl.command.options

enum class ZplMediaType(val value: String) {
THERMAL_TRANSFER("T"),
DIRECT_TRANSFER("D");

override fun toString(): String {
return value
}
}
44 changes: 44 additions & 0 deletions src/test/kotlin/com/sainsburys/k2zpl/command/MediaTypeTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.sainsburys.k2zpl.command

import com.sainsburys.k2zpl.command.options.ZplMediaType
import com.sainsburys.k2zpl.k2zpl
import com.sainsburys.k2zpl.testBuildString
import io.kotest.core.spec.IsolationMode
import io.kotest.core.spec.style.DescribeSpec
import io.kotest.data.forAll
import io.kotest.data.headers
import io.kotest.data.row
import io.kotest.data.table
import io.kotest.matchers.shouldBe

class MediaTypeTest : DescribeSpec({

isolationMode = IsolationMode.InstancePerLeaf

describe("MediaType") {

val subject = MediaType(type = ZplMediaType.DIRECT_TRANSFER)

it("outputs correct command") {
table(
headers("media type"),
ZplMediaType.entries.map { row(it) }
).forAll { type ->
subject.copy(type = type).testBuildString() shouldBe "^MT${type}"
}
}
}
describe("mediaType extension function") {
it("outputs correct command") {
table(
headers("media type"),
ZplMediaType.entries.map { row(it) }
).forAll { type ->
val result = k2zpl {
mediaType(type)
}
result shouldBe "^MT${type}\n"
}
}
}
})

0 comments on commit 05e8503

Please sign in to comment.