From 469e8f80d51278322ee2337394292f7d874ac406 Mon Sep 17 00:00:00 2001 From: JG1VPP Date: Sat, 6 Jul 2024 18:59:50 +0900 Subject: [PATCH] extract postal code from JARL summary sheet --- app/models/models.scala | 15 ++++++++++++++- app/views/comps/file.scala.html | 1 + build.sbt | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/models/models.scala b/app/models/models.scala index 4e953c8..027d814 100644 --- a/app/models/models.scala +++ b/app/models/models.scala @@ -403,6 +403,8 @@ class RankingTableToJson(implicit in: Injections) { * @param decoder 対象のサマリーシート */ class SheetDecoderToJson(decoder: SheetDecoder) { + val postal = "[\\u3012\\u3020]\\s*?\\d{3}-?\\d{4}".r + /** * サマリーシートの内容をJSONの文字列に変換します。 * @@ -411,10 +413,21 @@ class SheetDecoderToJson(decoder: SheetDecoder) { def json = Json.stringify(Json.toJson(Map( "call" -> decoder.getString("CALLSIGN"), "name" -> decoder.getString("NAME"), - "addr" -> decoder.getString("ADDRESS"), + "post" -> post(decoder.getString("ADDRESS"))._1.trim, + "addr" -> post(decoder.getString("ADDRESS"))._2.trim, "mail" -> decoder.getString("EMAIL"), "note" -> decoder.getString("COMMENTS") ))) + + /** + * 住所から郵便番号と残りの文字列を抽出します。 + * + * @return 郵便番号と残りの文字列 + */ + def post(addr: String): (String, String) = { + val mat = postal.findFirstIn(addr.toUpperCase) + (mat.mkString, addr.replace(mat.mkString, "")) + } } diff --git a/app/views/comps/file.scala.html b/app/views/comps/file.scala.html index f59fa1c..5ac7a1a 100644 --- a/app/views/comps/file.scala.html +++ b/app/views/comps/file.scala.html @@ -48,6 +48,7 @@

const json = JSON.parse(data); if(!$('#@{form("station.call").id}').val()) $('#@{form("station.call").id}').val(json.call); if(!$('#@{form("station.name").id}').val()) $('#@{form("station.name").id}').val(json.name); + if(!$('#@{form("station.post").id}').val()) $('#@{form("station.post").id}').val(json.post); if(!$('#@{form("station.addr").id}').val()) $('#@{form("station.addr").id}').val(json.addr); if(!$('#@{form("station.mail").id}').val()) $('#@{form("station.mail").id}').val(json.mail); if(!$('#@{form("station.note").id}').val()) $('#@{form("station.note").id}').val(json.note); diff --git a/build.sbt b/build.sbt index db219e3..cdb039f 100644 --- a/build.sbt +++ b/build.sbt @@ -6,7 +6,7 @@ libraryDependencies ++= Seq( filters, guice, jdbc, - "qxsl" % "qxsl" % "0.1.289", + "qxsl" % "qxsl" % "0.1.290", "org.jruby" % "jruby-core" % "9.+", "com.h2database" % "h2" % "1.4.+", "com.typesafe.play" %% "play-mailer" % "7.0.+",