Skip to content

Commit

Permalink
add ktlint
Browse files Browse the repository at this point in the history
  • Loading branch information
mvmike committed Aug 28, 2023
1 parent 30bdd38 commit 81a715b
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 24 deletions.
21 changes: 21 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = false
max_line_length = 120
tab_width = 4

[*.{yml, yaml, md, json, tf, sh}]
indent_size = 2

[*.{kt,kts}]
# https://www.jetbrains.com/help/idea/configuring-code-style.html#editorconfig
ij_kotlin_name_count_to_use_star_import = 999
ij_kotlin_name_count_to_use_star_import_for_members = 999
# https://pinterest.github.io/ktlint/rules/configuration-ktlint/#disabled-rules
ktlint_standard_trailing-comma-on-call-site = disabled
ktlint_standard_trailing-comma-on-declaration-site = disabled
4 changes: 4 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ plugins {
application
// https://kotlinlang.org/docs/releases.html#release-details
kotlin("jvm") version "1.9.10"
// https://github.com/jeremymailen/kotlinter-gradle/releases
id("org.jmailen.kotlinter") version "3.16.0"
}


Expand Down Expand Up @@ -46,6 +48,8 @@ tasks.apply {
}

defaultTasks(
//"formatKotlin",
"lintKotlin",
"clean",
"build"
)
15 changes: 8 additions & 7 deletions src/main/kotlin/cat/mvmike/numbertotext/NumberToText.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,18 @@ object NumberToText {
amount: Double,
currency: String? = null
): String {

// initial validations
amount.checkMinSize()
amount.checkMaxSize()
val intPart = amount.toInt()
val decimalPart = ((amount - intPart) * 100).roundToInt()
return (Thousands(intPart).get()
+ Units(intPart, intPart == 0).get()
+ Units(intPart).getCurrency(currency)
+ Cents(decimalPart).get()
+ Cents(decimalPart).getCurrency(currency))
return (
Thousands(intPart).get() +
Units(intPart, intPart == 0).get() +
Units(intPart).getCurrency(currency) +
Cents(decimalPart).get() +
Cents(decimalPart).getCurrency(currency)
)
}

private fun Double.checkMinSize() {
Expand All @@ -46,4 +47,4 @@ object NumberToText {
private fun Double.checkMaxSize() {
if (this >= MAX_VALUE) throw InvalidParameterException(MAX_VALUE_ERROR)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ object Constants {
const val DEC_SEPARATOR = "amb"

const val DEC_CURRENCY = "cèntim"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ fun getLiteral(value: Int, minValue: NumberLiteral, maxValue: NumberLiteral) =

fun Int.isEqualTo(numberLiteral: NumberLiteral) = this == numberLiteral.value

fun String.isEqualTo(numberLiteral: NumberLiteral) = this == numberLiteral.literal
fun String.isEqualTo(numberLiteral: NumberLiteral) = this == numberLiteral.literal
5 changes: 3 additions & 2 deletions src/main/kotlin/cat/mvmike/numbertotext/magnitude/Cents.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import cat.mvmike.numbertotext.language.Constants.DEC_SEPARATOR
import cat.mvmike.numbertotext.language.Constants.EMPTY
import cat.mvmike.numbertotext.language.Constants.PLURAL
import cat.mvmike.numbertotext.language.Constants.SPACE
import cat.mvmike.numbertotext.language.NumberLiteral.N_0
import cat.mvmike.numbertotext.language.NumberLiteral.N_1
import cat.mvmike.numbertotext.language.isEqualTo
import cat.mvmike.numbertotext.language.NumberLiteral.*

class Cents(private val number: Int) {

Expand All @@ -27,4 +28,4 @@ class Cents(private val number: Int) {
number.isEqualTo(N_1) -> SPACE + DEC_CURRENCY
else -> SPACE + DEC_CURRENCY + PLURAL
}
}
}
14 changes: 12 additions & 2 deletions src/main/kotlin/cat/mvmike/numbertotext/magnitude/Hundreds.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,17 @@ import cat.mvmike.numbertotext.language.Constants.DASH
import cat.mvmike.numbertotext.language.Constants.EMPTY
import cat.mvmike.numbertotext.language.Constants.PLURAL
import cat.mvmike.numbertotext.language.NumberLiteral
import cat.mvmike.numbertotext.language.NumberLiteral.*
import cat.mvmike.numbertotext.language.NumberLiteral.N_0
import cat.mvmike.numbertotext.language.NumberLiteral.N_1
import cat.mvmike.numbertotext.language.NumberLiteral.N_100
import cat.mvmike.numbertotext.language.NumberLiteral.N_2
import cat.mvmike.numbertotext.language.NumberLiteral.N_3
import cat.mvmike.numbertotext.language.NumberLiteral.N_4
import cat.mvmike.numbertotext.language.NumberLiteral.N_5
import cat.mvmike.numbertotext.language.NumberLiteral.N_6
import cat.mvmike.numbertotext.language.NumberLiteral.N_7
import cat.mvmike.numbertotext.language.NumberLiteral.N_8
import cat.mvmike.numbertotext.language.NumberLiteral.N_9
import cat.mvmike.numbertotext.language.getLiteral

class Hundreds(private val number: Int) {
Expand All @@ -31,4 +41,4 @@ class Hundreds(private val number: Int) {

fun Int.modOfHundred() = this % N_100.value

fun Int.isMultipleOfHundreds() = N_0.value == this.modOfHundred()
fun Int.isMultipleOfHundreds() = N_0.value == this.modOfHundred()
15 changes: 13 additions & 2 deletions src/main/kotlin/cat/mvmike/numbertotext/magnitude/Tens.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,18 @@ import cat.mvmike.numbertotext.language.Constants.AND
import cat.mvmike.numbertotext.language.Constants.DASH
import cat.mvmike.numbertotext.language.Constants.EMPTY
import cat.mvmike.numbertotext.language.NumberLiteral
import cat.mvmike.numbertotext.language.NumberLiteral.*
import cat.mvmike.numbertotext.language.NumberLiteral.N_0
import cat.mvmike.numbertotext.language.NumberLiteral.N_1
import cat.mvmike.numbertotext.language.NumberLiteral.N_10
import cat.mvmike.numbertotext.language.NumberLiteral.N_20
import cat.mvmike.numbertotext.language.NumberLiteral.N_30
import cat.mvmike.numbertotext.language.NumberLiteral.N_40
import cat.mvmike.numbertotext.language.NumberLiteral.N_50
import cat.mvmike.numbertotext.language.NumberLiteral.N_60
import cat.mvmike.numbertotext.language.NumberLiteral.N_70
import cat.mvmike.numbertotext.language.NumberLiteral.N_80
import cat.mvmike.numbertotext.language.NumberLiteral.N_9
import cat.mvmike.numbertotext.language.NumberLiteral.N_90
import cat.mvmike.numbertotext.language.getStringLiteral

class Tens(private val number: Int) {
Expand All @@ -28,4 +39,4 @@ class Tens(private val number: Int) {

fun Int.modOfTen() = this % N_10.value

fun Int.isMultipleOfTens() = N_0.value == this.modOfTen()
fun Int.isMultipleOfTens() = N_0.value == this.modOfTen()
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ package cat.mvmike.numbertotext.magnitude

import cat.mvmike.numbertotext.language.Constants.EMPTY
import cat.mvmike.numbertotext.language.Constants.SPACE
import cat.mvmike.numbertotext.language.NumberLiteral.*
import cat.mvmike.numbertotext.language.NumberLiteral.N_0
import cat.mvmike.numbertotext.language.NumberLiteral.N_1
import cat.mvmike.numbertotext.language.NumberLiteral.N_1000
import cat.mvmike.numbertotext.language.isEqualTo

class Thousands(private val number: Int) {
Expand All @@ -25,4 +27,4 @@ class Thousands(private val number: Int) {
}
}

private fun Int.isMultipleOfThousand() = N_0.value == (this % N_1000.value)
private fun Int.isMultipleOfThousand() = N_0.value == (this % N_1000.value)
8 changes: 3 additions & 5 deletions src/main/kotlin/cat/mvmike/numbertotext/magnitude/Units.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ package cat.mvmike.numbertotext.magnitude
import cat.mvmike.numbertotext.language.Constants.EMPTY
import cat.mvmike.numbertotext.language.Constants.PLURAL
import cat.mvmike.numbertotext.language.Constants.SPACE
import cat.mvmike.numbertotext.language.NumberLiteral.*
import cat.mvmike.numbertotext.language.NumberLiteral.N_1
import cat.mvmike.numbertotext.language.NumberLiteral.N_100

class Units(
private val number: Int,
Expand Down Expand Up @@ -35,7 +36,4 @@ class Units(
number.modOfTen() -> EMPTY
else -> PLURAL
}
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ class NumberLiteralToTextTest {
TestProperties(
amount = 0.0,
currency = null,
expectedOutput = "zero"),
expectedOutput = "zero"
),
TestProperties(
amount = 0.0,
currency = "euro",
Expand Down Expand Up @@ -170,4 +171,4 @@ class NumberLiteralToTextTest {
val currency: String?,
val expectedOutput: String
)
}
}

0 comments on commit 81a715b

Please sign in to comment.