Skip to content

Commit

Permalink
Merge branch 'master' into renovate/configure
Browse files Browse the repository at this point in the history
  • Loading branch information
dvulpe authored Jun 14, 2020
2 parents 1b87bef + 9a1ea3d commit a8dffcc
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 102 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/scala.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Scala CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up JDK
uses: actions/setup-java@v1
with:
java-version: 11
- name: Run tests
run: ./sbt test
8 changes: 3 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ name := "ing-parser"

version := "1.0"

scalaVersion := "2.11.7"
scalaVersion := "2.12.8"

libraryDependencies += "joda-time" % "joda-time" % "1.6.2"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.1.2" % "test"

libraryDependencies += "org.scalatest" %% "scalatest" % "2.2.6" % "test"

libraryDependencies += "org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.4"
libraryDependencies += "org.scala-lang.modules" %% "scala-parser-combinators" % "1.1.2"



1 change: 1 addition & 0 deletions project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.3.8
4 changes: 0 additions & 4 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.5.1")

addSbtPlugin("de.johoop" % "jacoco4sbt" % "2.1.1")

42 changes: 42 additions & 0 deletions sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

set -e

sbtver=1.3.8
sbtjar=.sbt-launch.jar
sha256=305e7202756bae9887810e3a81070ccd94d966c60e5e3e3c6082455ab33eb59a
sbtrepo=https://repo1.maven.org/maven2/org/scala-sbt/sbt-launch

validjar() {
checksum=`openssl dgst -sha256 $sbtjar | awk '{ print $2 }'`
[ "$checksum" = $sha256 ]
}

if [ -f $sbtjar ] && ! validjar ; then
echo "bad $sbtjar" >&2
mv $sbtjar "${sbtjar}.invalid"
fi

if [ ! -f $sbtjar ]; then
echo "downloading $sbtjar" >&2
curl -L --silent --fail -o $sbtjar $sbtrepo/$sbtver/sbt-launch.jar
fi

if ! validjar ; then
echo "bad $sbtjar. delete $sbtjar and run $0 again." >&2
exit 1
fi

[ -f ~/.sbtconfig ] && . ~/.sbtconfig

java -ea \
$SBT_OPTS \
$JAVA_OPTS \
-XX:ReservedCodeCacheSize=128m \
-XX:SurvivorRatio=128 \
-XX:MaxTenuringThreshold=0 \
-Xss8M \
-Xms512M \
-Xmx2G \
-server \
-jar $sbtjar "$@"
4 changes: 2 additions & 2 deletions src/main/scala/ro/dvulpe/ingparser/CSVParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ trait CSVParser extends RegexParsers {
}
}

val nonEscaped = (TXT *) ^^ {
val plain = (TXT *) ^^ {
case ls => ls.mkString
}

val field = escaped | nonEscaped
val field = escaped | plain

val record = repsep(field, COMMA)

Expand Down
10 changes: 5 additions & 5 deletions src/main/scala/ro/dvulpe/ingparser/INGParser.scala
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package ro.dvulpe.ingparser

import org.joda.time.DateTime
import java.time.LocalDate

import scala.util.Try
import scala.util.parsing.combinator._

case class Summary(date: DateTime, details: String, debit: Option[BigDecimal], credit: Option[BigDecimal]) {
case class Summary(date: LocalDate, details: String, debit: Option[BigDecimal], credit: Option[BigDecimal]) {
def asList = date :: details :: debit.getOrElse("") :: credit.getOrElse("") :: Nil

def asString = s"${date.toLocalDate.toString} - $details, Debit: $debit, Credit: $credit"
def asString = s"${date.toString} - $details, Debit: $debit, Credit: $credit"
}

case class IngRecord(summary: Summary, details: Seq[String]) {
Expand All @@ -21,13 +21,13 @@ object INGParser extends RegexParsers with CSVParser {

def asDate(data: String) = Parser {
in: Input =>
Try(data.asDateTime) match {
Try(data.asLocalDate) match {
case scala.util.Success(localDate) => Success(localDate, in)
case scala.util.Failure(ex) => Failure(ex.toString, in)
}
}

val date: Parser[DateTime] = field >> asDate
val date: Parser[LocalDate] = field >> asDate

def asDecimal(data: String) = Parser {
in: Input =>
Expand Down
20 changes: 0 additions & 20 deletions src/main/scala/ro/dvulpe/ingparser/ParenthesisParser.scala

This file was deleted.

41 changes: 0 additions & 41 deletions src/main/scala/ro/dvulpe/ingparser/Parser.scala

This file was deleted.

4 changes: 2 additions & 2 deletions src/main/scala/ro/dvulpe/ingparser/Transaction.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package ro.dvulpe.ingparser

import org.joda.time.DateTime
import java.time.LocalDate

case class Transaction(id: String, date: DateTime, notes: String, amount: BigDecimal,
case class Transaction(id: String, date: LocalDate, notes: String, amount: BigDecimal,
payee: String, accountRef: Option[String], bank: Option[String],
reference: String)

Expand Down
9 changes: 6 additions & 3 deletions src/main/scala/ro/dvulpe/ingparser/package.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package ro.dvulpe

import org.joda.time.format.DateTimeFormat
import java.text.{DecimalFormat, NumberFormat}
import java.time.LocalDate
import java.time.format.{DateTimeFormatter, FormatStyle}
import java.util.Locale
import java.text.{NumberFormat, DecimalFormat}

package object ingparser {
implicit def richString(input: String) = new {
def asDateTime = DateTimeFormat.forPattern("dd MMMMM yyyy").withLocale(new Locale("RO")).parseDateTime(input)
private val localDateFormatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG).withLocale(new Locale("RO"))

def asLocalDate = LocalDate.parse(input, localDateFormatter)

def asDecimal = {
val format: DecimalFormat = NumberFormat.getInstance(new Locale("RO")).asInstanceOf[DecimalFormat]
Expand Down
11 changes: 4 additions & 7 deletions src/test/scala/ro/dvulpe/ingparser/INGParserTest.scala
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
package ro.dvulpe.ingparser

import org.scalatest.FunSuite
import org.joda.time.DateTime
import java.time.LocalDate
import org.scalatest.funsuite.AnyFunSuite

class INGParserTest extends FunSuite {
class INGParserTest extends AnyFunSuite {

test("transaction detail line should be parsed") {
val input = ",Beneficiar: RCS AND RDS SA,,"
val result = INGParser.parseTest(input, INGParser.transDetail)
println(result)
assert(result === "Beneficiar: RCS AND RDS SA")
}

test("transaction details lines should be parsed") {
val input = ",Beneficiar: RCS AND RDS SA,,\n,Banca: INGB CENTRALA,,\n,Referinta: 70979872,,"
val result = INGParser.parseTest(input, INGParser.transDetails)
println(result)
assert(result === List("Beneficiar: RCS AND RDS SA", "Banca: INGB CENTRALA", "Referinta: 70979872"))
}

test("transaction summary line should be parsed") {
val input = "30 septembrie 2013,Plata debit direct,\"120,19\","
val result = INGParser.parseTest(input, INGParser.summaryLine)
assert(result === Summary(new DateTime("2013-09-30T00:00:00.000+03:00"), "Plata debit direct", Some(BigDecimal("120.19")), None))
assert(result === Summary(LocalDate.of(2013, 9, 30), "Plata debit direct", Some(BigDecimal("120.19")), None))
}

test("transaction with details should be parsed") {
Expand Down Expand Up @@ -53,7 +51,6 @@ class INGParserTest extends FunSuite {
val input = "Data,Detalii tranzactie,Debit,Credit\n30 septembrie 2013,Plata debit direct,\"120,19\",\n30 septembrie 2013,Plata debit direct,\"120,19\",\n"
val result = INGParser.parseRecords(input)
assert(result.size === 2)

}

}
13 changes: 0 additions & 13 deletions src/test/scala/ro/dvulpe/ingparser/ParenthesisParserTest.scala

This file was deleted.

0 comments on commit a8dffcc

Please sign in to comment.