Skip to content

Commit

Permalink
extract postal code from JARL summary sheet
Browse files Browse the repository at this point in the history
  • Loading branch information
JG1VPP committed Jul 6, 2024
1 parent ba306fa commit 469e8f8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
15 changes: 14 additions & 1 deletion app/models/models.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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の文字列に変換します。
*
Expand All @@ -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, ""))
}
}


Expand Down
1 change: 1 addition & 0 deletions app/views/comps/file.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ <h3 class='card-header'>
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);
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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.+",
Expand Down

0 comments on commit 469e8f8

Please sign in to comment.