jma_code 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +49 -0
  3. data/data/20130523_AreaMarineAJ/AreaMarineA.csv +78 -0
  4. data/data/20130523_AreaMarineAJ/AreaMarineJ.csv +67 -0
  5. data/data/20201026_WmoObservingStations.csv +176 -0
  6. data/data/20240216_AreaInformationCity-AreaForecastLocalM/AreaForecastLocalM/357/274/210/343/202/263/343/203/274/343/203/210/343/202/231/350/241/250/357/274/211.csv +616 -0
  7. data/data/20240216_AreaInformationCity-AreaForecastLocalM/AreaForecastLocalM/357/274/210/351/226/242/344/277/202/350/241/250/343/200/200/347/253/234/345/267/273/346/263/250/346/204/217/346/203/205/345/240/261.csv +391 -0
  8. data/data/20240216_AreaInformationCity-AreaForecastLocalM/AreaForecastLocalM/357/274/210/351/226/242/344/277/202/350/241/250/343/200/200/350/255/246/345/240/261/343/203/273/346/263/250/346/204/217/345/240/261.csv +399 -0
  9. data/data/20240216_AreaInformationCity-AreaForecastLocalM/AreaInformationCity.csv +2094 -0
  10. data/data/20240315_RiverOffice.csv +163 -0
  11. data/data/20240325_PointAmedas/ame_master.csv +1378 -0
  12. data/data/20240325_PointAmedas/snow_master.csv +341 -0
  13. data/data/20240418_WaterLevelStation.csv +641 -0
  14. data/data/Volcano_Earthquake/20240618_AdditionalCommentEarthquake.csv +72 -0
  15. data/data/Volcano_Earthquake/20240618_AreaEpicenter.csv +348 -0
  16. data/data/Volcano_Earthquake/20240618_AreaEpicenterAbbreviation.csv +171 -0
  17. data/data/Volcano_Earthquake/20240618_AreaEpicenterDetail.csv +762 -0
  18. data/data/Volcano_Earthquake/20240618_AreaEpicenterSuppliment.csv +46 -0
  19. data/data/Volcano_Earthquake/20240618_AreaForecastEEW.csv +19 -0
  20. data/data/Volcano_Earthquake/20240618_AreaForecastLocalEEW.csv +61 -0
  21. data/data/Volcano_Earthquake/20240618_AreaForecastLocalE_ AreaInformationCity_ PointSeismicIntensity.csv +4377 -0
  22. data/data/Volcano_Earthquake/20240618_AreaForecastLocalE_AreaInformationCity_PointRealtimeIntensity.csv +666 -0
  23. data/data/Volcano_Earthquake/20240618_AreaForecastLocalE_PointSeismicLgIntensity.csv +708 -0
  24. data/data/Volcano_Earthquake/20240618_AreaInformationPrefectureEarthquake.csv +52 -0
  25. data/data/Volcano_Earthquake/20240618_AreaTsunami.csv +103 -0
  26. data/data/Volcano_Earthquake/20240618_CoastTsunami.csv +70 -0
  27. data/data/Volcano_Earthquake/20240618_EarthquakeForecast.csv +11 -0
  28. data/data/Volcano_Earthquake/20240618_EarthquakeInformation.csv +28 -0
  29. data/data/Volcano_Earthquake/20240618_EarthquakeWarning.csv +7 -0
  30. data/data/Volcano_Earthquake/20240618_PointTsunami.csv +560 -0
  31. data/data/Volcano_Earthquake/20240618_PointVolcano.csv +125 -0
  32. data/data/Volcano_Earthquake/20240618_TokaiInformation.csv +8 -0
  33. data/data/Volcano_Earthquake/20240618_TsunamiWarning.csv +14 -0
  34. data/data/Volcano_Earthquake/20240618_VolcanicWarning.csv +55 -0
  35. data/lib/jma_code/area_flood_forecast.rb +30 -0
  36. data/lib/jma_code/area_forecast_local.rb +52 -0
  37. data/lib/jma_code/area_information_city.rb +97 -0
  38. data/lib/jma_code/area_marine.rb +91 -0
  39. data/lib/jma_code/ext/blank.rb +61 -0
  40. data/lib/jma_code/point_amedas.rb +134 -0
  41. data/lib/jma_code/river_office.rb +30 -0
  42. data/lib/jma_code/version.rb +3 -0
  43. data/lib/jma_code/water_level_station.rb +44 -0
  44. data/lib/jma_code/wmo_observing_station.rb +68 -0
  45. data/lib/jma_code.rb +13 -0
  46. metadata +100 -0
@@ -0,0 +1,125 @@
1
+ "PointVolcano コード表
2
+ (種別:""火山名"")
3
+ ",,,,,,
4
+ PointVolcano,,,,,,
5
+ Code,Name,ふりがな,備考,,,
6
+ 101,知床硫黄山,しれとこいおうざん,,,,
7
+ 102,羅臼岳,らうすだけ,,,,
8
+ 103,摩周,ましゅう,,,,
9
+ 104,アトサヌプリ,あとさぬぷり,,,,
10
+ 105,雌阿寒岳,めあかんだけ,,,,
11
+ 106,丸山,まるやま,,,,
12
+ 107,大雪山,たいせつざん,,,,
13
+ 108,十勝岳,とかちだけ,,,,
14
+ 109,樽前山,たるまえさん,,,,
15
+ 110,恵庭岳,えにわだけ,,,,
16
+ 111,倶多楽,くったら,,,,
17
+ 112,有珠山,うすざん,,,,
18
+ 113,北海道駒ヶ岳,ほっかいどうこまがたけ,,,,
19
+ 114,恵山,えさん,,,,
20
+ 115,渡島大島,おしまおおしま,,,,
21
+ 116,利尻山,りしりざん,,,,
22
+ 117,羊蹄山,ようていさん,,,,
23
+ 118,ニセコ,にせこ,,,,
24
+ 119,天頂山,てんちょうざん,,,,
25
+ 120,雄阿寒岳,おあかんだけ,,,,
26
+ 151,茂世路岳,もよろだけ,,,,
27
+ 152,散布山,ちりっぷさん,,,,
28
+ 153,指臼岳,さしうすだけ,,,,
29
+ 154,小田萌山,おだもいさん,,,,
30
+ 155,択捉焼山,えとろふやけやま,,,,
31
+ 156,択捉阿登佐岳,えとろふあとさぬぷり,,,,
32
+ 157,ベルタルベ山,べるたるべさん,,,,
33
+ 158,爺爺岳,ちゃちゃだけ,,,,
34
+ 159,羅臼山,らうすさん,,,,
35
+ 160,泊山,とまりやま,,,,
36
+ 161,ルルイ岳,るるいだけ,,,,
37
+ 201,恐山,おそれざん,,,,
38
+ 202,岩木山,いわきさん,,,,
39
+ 203,八甲田山,はっこうださん,,,,
40
+ 204,十和田,とわだ,,,,
41
+ 205,秋田焼山,あきたやけやま,,,,
42
+ 206,八幡平,はちまんたい,,,,
43
+ 207,岩手山,いわてさん,,,,
44
+ 208,秋田駒ヶ岳,あきたこまがたけ,,,,
45
+ 209,鳥海山,ちょうかいさん,,,,
46
+ 210,栗駒山,くりこまやま,,,,
47
+ 211,鳴子,なるこ,,,,
48
+ 212,蔵王山,ざおうざん(ざおうさん),2つのふりがなを併記,,,
49
+ 213,吾妻山,あづまやま,,,,
50
+ 214,安達太良山,あだたらやま,,,,
51
+ 215,磐梯山,ばんだいさん,,,,
52
+ 216,燧ヶ岳,ひうちがたけ,,,,
53
+ 217,肘折,ひじおり,,,,
54
+ 218,沼沢,ぬまざわ,,,,
55
+ 301,那須岳,なすだけ,,,,
56
+ 302,日光白根山,にっこうしらねさん,,,,
57
+ 303,赤城山,あかぎさん,,,,
58
+ 304,榛名山,はるなさん,,,,
59
+ 305,草津白根山,くさつしらねさん,,,,
60
+ 306,浅間山,あさまやま,,,,
61
+ 307,新潟焼山,にいがたやけやま,,,,
62
+ 308,妙高山,みょうこうさん,,,,
63
+ 309,弥陀ヶ原,みだがはら,,,,
64
+ 310,焼岳,やけだけ,,,,
65
+ 311,乗鞍岳,のりくらだけ,,,,
66
+ 312,御嶽山,おんたけさん,,,,
67
+ 313,白山,はくさん,,,,
68
+ 314,富士山,ふじさん,,,,
69
+ 315,箱根山,はこねやま,,,,
70
+ 316,伊豆東部火山群,いずとうぶかざんぐん,,,,
71
+ 317,伊豆大島,いずおおしま,,,,
72
+ 318,新島,にいじま,,,,
73
+ 319,神津島,こうづしま,,,,
74
+ 320,三宅島,みやけじま,,,,
75
+ 321,八丈島,はちじょうじま,,,,
76
+ 322,青ヶ島,あおがしま,,,,
77
+ 323,ベヨネース列岩,べよねーすれつがん,,,,
78
+ 324,須美寿島,すみすじま,,,,
79
+ 325,伊豆鳥島,いずとりしま,,,,
80
+ 326,西之島,にしのしま,,,,
81
+ 327,海徳海山,かいとくかいざん,,,,
82
+ 328,噴火浅根,ふんかあさね,,,,
83
+ 329,硫黄島,いおうとう,,,,
84
+ 330,北福徳堆,きたふくとくたい,,,,
85
+ 331,福徳岡ノ場,ふくとくおかのば,,,,
86
+ 333,高原山,たかはらやま,,,,
87
+ 334,横岳,よこだけ,,,,
88
+ 335,アカンダナ山,あかんだなやま,,,,
89
+ 336,利島,としま,,,,
90
+ 337,御蔵島,みくらじま,,,,
91
+ 338,孀婦岩,そうふがん,,,,
92
+ 339,海形海山,かいかたかいざん,,,,
93
+ 340,南日吉海山,みなみひよしかいざん,,,,
94
+ 341,日光海山,にっこうかいざん,,,,
95
+ 342,男体山,なんたいさん,,,,
96
+ 350,草津白根山(白根山(湯釜付近)),くさつしらねさん(しらねさん(ゆがまふきん)),,,,
97
+ 351,草津白根山(本白根山),くさつしらねさん(もとしらねさん),,,,
98
+ 401,三瓶山,さんべさん,,,,
99
+ 502,九重山,くじゅうさん,,,,
100
+ 503,阿蘇山,あそさん,,,,
101
+ 504,雲仙岳,うんぜんだけ,,,,
102
+ 505,霧島山,きりしまやま,,,,
103
+ 506,桜島,さくらじま,,,,
104
+ 507,開聞岳,かいもんだけ,,,,
105
+ 508,薩摩硫黄島,さつまいおうじま,,,,
106
+ 509,口永良部島,くちのえらぶじま,,,,
107
+ 510,中之島,なかのしま,,,,
108
+ 511,諏訪之瀬島,すわのせじま,,,,
109
+ 512,阿武火山群,あぶかざんぐん,,,,
110
+ 513,鶴見岳・伽藍岳,つるみだけ・がらんだけ,,,,
111
+ 514,由布岳,ゆふだけ,,,,
112
+ 515,福江火山群,ふくえかざんぐん,,,,
113
+ 516,米丸・住吉池,よねまる・すみよしいけ,,,,
114
+ 517,若尊,わかみこ,,,,
115
+ 518,池田・山川,いけだ・やまがわ,,,,
116
+ 519,口之島,くちのしま,,,,
117
+ 550,霧島山(御鉢),きりしまやま(おはち),,,,
118
+ 551,霧島山(新燃岳),きりしまやま(しんもえだけ),,,,
119
+ 552,霧島山(えびの高原(硫黄山)周辺),きりしまやま(えびのこうげん(いおうやま)しゅうへん),,,,
120
+ 553,霧島山(大幡池),きりしまやま(おおはたいけ),,,,
121
+ 601,硫黄鳥島,いおうとりしま,,,,
122
+ 602,西表島北北東海底火山,いりおもてじまほくほくとうかいていかざん,,,,
123
+ 900,全国の活火山,ぜんこくのかつかざん,,,,
124
+ 901,その他の活火山,そのたのかつかざん,,,,
125
+ 902,新たな活火山,あらたなかつかざん,,,,
@@ -0,0 +1,8 @@
1
+ "TokaiInformation コード表
2
+ (種別:""東海関連情報番号"")
3
+ ",,,,
4
+ 東海関連情報番号,,,,
5
+ Code,Name,,,
6
+ 000, 臨時,,,
7
+ 020, 定例,,,
8
+ 900, 終了,,,
@@ -0,0 +1,14 @@
1
+ "TsunamiWarning コード表
2
+ (種別:""警報等情報要素/津波警報・注意報・予報"")",,,,,
3
+ TsunamiWarning,,,,,
4
+ Code,Name,備考,,,
5
+ 00,津波なし,,,,
6
+ 50,警報解除,大津波警報または津波警報の解除,,,
7
+ 51,津波警報,,,,
8
+ 52,大津波警報,,,,
9
+ 53,大津波警報:発表,"大津波警報の新規発表または切替(移行措置用電文のCodeには""52""を記載する)",,,
10
+ 60,津波注意報解除,,,,
11
+ 62,津波注意報,,,,
12
+ 71,津波予報(若干の海面変動),,,,
13
+ 72,津波予報(若干の海面変動),津波注意報解除、津波予報(若干の海面変動)への切替,,,
14
+ 73,津波予報(若干の海面変動),大津波警報または津波警報の解除、津波予報(若干の海面変動)への切替,,,
@@ -0,0 +1,55 @@
1
+ "VolcanicWarning コード表
2
+ (種別:""警報等情報要素/噴火警報・予報等"")
3
+ ",,,,,
4
+ VolcanicWarning,,,,,
5
+ Code,Name,備考,,,
6
+ 01,噴火警報,,,,
7
+ 02,火口周辺警報,,,,
8
+ 03,噴火警報(周辺海域),,,,
9
+ 04,噴火予報:警報解除,,,,
10
+ 05,噴火予報,,,,
11
+ 06,降灰予報(定時),,,,
12
+ 07,降灰予報(速報),,,,
13
+ 08,降灰予報(詳細),,,,
14
+ 11,レベル1(活火山であることに留意),,,,
15
+ 12,レベル2(火口周辺規制),,,,
16
+ 13,レベル3(入山規制),,,,
17
+ 14,レベル4(高齢者等避難),,,,
18
+ 15,レベル5(避難),,,,
19
+ 21,活火山であることに留意,,,,
20
+ 22,火口周辺危険,,,,
21
+ 23,入山危険,,,,
22
+ 24,山麓厳重警戒,,,,
23
+ 25,居住地域厳重警戒,,,,
24
+ 31,海上警報(噴火警報),,,,
25
+ 32,海上警報(噴火警報解除),,,,
26
+ 33,海上予報(噴火予報),,,,
27
+ 35,活火山であることに留意(海底火山),,,,
28
+ 36,周辺海域警戒,,,,
29
+ 41 ,噴火警報:避難等,,,,
30
+ 42,噴火警報:入山規制等,,,,
31
+ 43,火口周辺警報:入山規制等,,,,
32
+ 44,噴火警報(周辺海域):周辺海域警戒,,,,
33
+ 45,活火山であることに留意,,,,
34
+ 46,噴火警報:当該居住地域厳重警戒,,,,
35
+ 47,噴火警報:当該山麓厳重警戒,噴火警報(山麓)の場合、46に代えて使用する。,,,
36
+ 48,噴火警報:火口周辺警戒,,,,
37
+ 49,火口周辺警報:火口周辺警戒,,,,
38
+ 51,爆発,,,,
39
+ 52,噴火,,,,
40
+ 53,噴火開始,平成26年12月から運用上使用しない,,,
41
+ 54,連続噴火継続,,,,
42
+ 55,連続噴火停止,,,,
43
+ 56,噴火多発,,,,
44
+ 61,爆発したもよう,,,,
45
+ 62,噴火したもよう,,,,
46
+ 63,噴火開始したもよう,平成26年12月から運用上使用しない,,,
47
+ 64,連続噴火が継続しているもよう,,,,
48
+ 65,連続噴火は停止したもよう,,,,
49
+ 70,降灰,,,,
50
+ 71,少量の降灰,,,,
51
+ 72,やや多量の降灰,,,,
52
+ 73,多量の降灰,,,,
53
+ 75,小さな噴石の落下,,,,
54
+ 91,不明,,,,
55
+ 99,その他の現象,,,,
@@ -0,0 +1,30 @@
1
+ require "csv"
2
+
3
+ module JMACode
4
+ class AreaFloodForecast < Struct.new(
5
+ :code, :name, :name_phonetic,
6
+ keyword_init: true
7
+ )
8
+ HEADERS = %i(code name name_phonetic)
9
+
10
+ class << self
11
+ def load_20230105(&block)
12
+ path = File.join(File.dirname(__FILE__), "../../data/20230105_AreaFloodForecast.csv")
13
+ File.open(path) do |f|
14
+ csv = CSV.new(f, headers: HEADERS, row_sep: "\r\n")
15
+ if block_given?
16
+ yield(csv)
17
+ else
18
+ load(csv, num_headers: 3, &block)
19
+ end
20
+ end
21
+ end
22
+
23
+ def load(csv, num_headers: 3)
24
+ csv.drop(num_headers).map do |row|
25
+ new(code: row[:code], name: row[:name], name_phonetic: row[:name_phonetic])
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,52 @@
1
+
2
+ module JMACode
3
+ using Blank
4
+
5
+ class AreaForecastLocal < Struct.new(
6
+ :code, :name, :name_phonetic, :used_by,
7
+ keyword_init: true
8
+ )
9
+ HEADERS = %i(
10
+ code
11
+ name
12
+ name_phonetic
13
+ )
14
+
15
+ class << self
16
+ attr_accessor :area_information_cities
17
+
18
+ def load_20240216(&block)
19
+ path = File.join(File.dirname(__FILE__), "../../data/20240216_AreaInformationCity-AreaForecastLocalM/AreaForecastLocalM(コード表).csv")
20
+ File.open(path) do |f|
21
+ csv = CSV.new(f, headers: HEADERS, row_sep: "\r\n")
22
+ if block_given?
23
+ yield(csv)
24
+ else
25
+ load(csv, num_headers: 3, &block)
26
+ end
27
+ end
28
+ end
29
+
30
+ def load(csv, num_headers: 3)
31
+ list = []
32
+ csv.each.with_index do |row, i|
33
+ next if i < num_headers
34
+ list << build_by_csv_row(row)
35
+ end
36
+ list
37
+ end
38
+
39
+ def build_by_csv_row(row)
40
+ new(
41
+ code: row[:code],
42
+ name: row[:name],
43
+ name_phonetic: row[:name_phonetic],
44
+ )
45
+ end
46
+ end
47
+
48
+ def area_information_city
49
+ @area_information_city ||= (self.class.area_information_cities || []).find{|x| x.area_forecast_local_code == code}
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,97 @@
1
+
2
+ module JMACode
3
+ using Blank
4
+
5
+ class AreaInformationCity < Struct.new(
6
+ :code, :name, :alt_name, :alt_name_phonetic,
7
+ :area_forecast_local_code, :used_by,
8
+ keyword_init: true
9
+ )
10
+ HEADERS = %i(
11
+ code
12
+ name
13
+ name_used_by_weather
14
+ name_phonetic_used_by_weather
15
+ area_forecast_local_code
16
+ used_by_weather_alert
17
+ used_by_tornado_alert
18
+ used_by_long_surge_alert
19
+ used_by_short_surge_alert
20
+ used_by_landslide_alert
21
+ used_by_flood_alert
22
+ name_used_by_earthquake
23
+ name_phonetic_used_by_earthquake
24
+ name_used_by_volcano
25
+ name_phonetic_used_by_volcano
26
+ name_used_by_uv
27
+ name_phonetic_used_by_uv
28
+ name_used_by_rainstorm_alert
29
+ name_phonetic_used_by_rainstorm_alert
30
+ )
31
+
32
+ class << self
33
+ attr_accessor :area_forecast_locals
34
+
35
+ def load_20240216(&block)
36
+ path = File.join(File.dirname(__FILE__), "../../data/20240216_AreaInformationCity-AreaForecastLocalM/AreaInformationCity.csv")
37
+ File.open(path) do |f|
38
+ csv = CSV.new(f, headers: HEADERS, row_sep: "\r\n")
39
+ if block_given?
40
+ yield(csv)
41
+ else
42
+ load(csv, num_headers: 3, &block)
43
+ end
44
+ end
45
+ end
46
+
47
+ def load(csv, num_headers: 3)
48
+ list = []
49
+ csv.each.with_index do |row, i|
50
+ next if i < num_headers
51
+ list << build_by_csv_row(row)
52
+ end
53
+ list
54
+ end
55
+
56
+ def build_by_csv_row(row)
57
+ alt_name, alt_name_phonetic = if row[:name_used_by_weather].present?
58
+ [row[:name_used_by_weather], row[:name_phonetic_used_by_weather]]
59
+ elsif row[:name_used_by_earthquake].present?
60
+ [row[:name_used_by_earthquake], row[:name_phonetic_used_by_earthquake]]
61
+ elsif row[:name_used_by_volcano].present?
62
+ [row[:name_used_by_volcano], row[:name_phonetic_used_by_volcano]]
63
+ elsif row[:name_used_by_uv].present?
64
+ [row[:name_used_by_uv], row[:name_phonetic_used_by_uv]]
65
+ elsif row[:name_used_by_rainstorm_alert].present?
66
+ [row[:name_used_by_rainstorm_alert], row[:name_phonetic_used_by_rainstorm_alert]]
67
+ else
68
+ []
69
+ end
70
+
71
+ new(
72
+ code: row[:code],
73
+ name: row[:name],
74
+ alt_name: alt_name,
75
+ alt_name_phonetic: alt_name_phonetic,
76
+ area_forecast_local_code: row[:area_forecast_local_code],
77
+ used_by: [
78
+ row[:used_by_weather_alert] == '1' ? :weather_alert : nil,
79
+ row[:used_by_tornado_alert] == '1' ? :tornado_alert : nil,
80
+ row[:used_by_long_surge_alert] == '1' ? :long_surge_alert : nil,
81
+ row[:used_by_short_surge_alert] == '1' ? :short_surge_alert : nil,
82
+ row[:used_by_landslide_alert] == '1' ? :landslide_alert : nil,
83
+ row[:used_by_flood_alert] == '1' ? :flood_alert : nil,
84
+ row[:name_used_by_earthquake].present? ? :earthquake : nil,
85
+ row[:name_used_by_volcano].present? ? :volcano : nil,
86
+ row[:name_used_by_uv].present? ? :uv : nil,
87
+ row[:name_used_by_rainstorm_alert].present? ? :rainstorm_alert : nil,
88
+ ].compact
89
+ )
90
+ end
91
+ end
92
+
93
+ def area_forecast_local
94
+ @area_forecast_local ||= (self.class.area_forecast_locals || []).find{|x| x.code == area_forecast_local_code}
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,91 @@
1
+ require "csv"
2
+
3
+ module JMACode::AreaMarine
4
+ class A < Struct.new(
5
+ :code, :name, :name_phonetic,
6
+ keyword_init: true
7
+ )
8
+ HEADERS = %i(
9
+ code
10
+ name
11
+ name_phonetic
12
+ )
13
+
14
+ class << self
15
+ def load_20130523(&block)
16
+ path = File.join(File.dirname(__FILE__), "../../data/20130523_AreaMarineAJ/AreaMarineA.csv")
17
+ File.open(path) do |f|
18
+ csv = CSV.new(f, headers: HEADERS, row_sep: "\r\n")
19
+ if block_given?
20
+ yield(csv)
21
+ else
22
+ load(csv, num_headers: 3, &block)
23
+ end
24
+ end
25
+ end
26
+
27
+ def load(csv, num_headers: 2)
28
+ list = []
29
+ csv.each.with_index do |row, i|
30
+ next if i < num_headers
31
+ list << build_by_csv_row(row)
32
+ end
33
+ list
34
+ end
35
+
36
+ def build_by_csv_row(row)
37
+ new(
38
+ code: row[:code],
39
+ name: row[:name],
40
+ name_phonetic: row[:name_phonetic],
41
+ )
42
+ end
43
+ end
44
+ end
45
+
46
+ class J < Struct.new(
47
+ :code, :name, :name_phonetic, :used_by_local_marine_warning, :used_by_volcanic_marine_warning,
48
+ keyword_init: true
49
+ )
50
+ HEADERS = %i(
51
+ code
52
+ name
53
+ name_phonetic
54
+ used_by_local_marine_warning
55
+ used_by_volcanic_marine_warning
56
+ )
57
+
58
+ class << self
59
+ def load_20130523(&block)
60
+ path = File.join(File.dirname(__FILE__), "../../data/20130523_AreaMarineAJ/AreaMarineJ.csv")
61
+ File.open(path) do |f|
62
+ csv = CSV.new(f, headers: HEADERS, row_sep: "\r\n")
63
+ if block_given?
64
+ yield(csv)
65
+ else
66
+ load(csv, num_headers: 4, &block)
67
+ end
68
+ end
69
+ end
70
+
71
+ def load(csv, num_headers: 2)
72
+ list = []
73
+ csv.each.with_index do |row, i|
74
+ next if i < num_headers
75
+ list << build_by_csv_row(row)
76
+ end
77
+ list
78
+ end
79
+
80
+ def build_by_csv_row(row)
81
+ new(
82
+ code: row[:code],
83
+ name: row[:name],
84
+ name_phonetic: row[:name_phonetic],
85
+ used_by_local_marine_warning: row[:used_by_local_marine_warning],
86
+ used_by_volcanic_marine_warning: row[:used_by_volcanic_marine_warning],
87
+ )
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,61 @@
1
+ module JMACode
2
+ module Blank
3
+ refine Object do
4
+ def blank?
5
+ respond_to?(:empty?) ? !!empty? : !self
6
+ end
7
+
8
+ def present?
9
+ !blank?
10
+ end
11
+
12
+ def presence
13
+ self if present?
14
+ end
15
+ end
16
+
17
+ refine NilClass do
18
+ def blank?
19
+ true
20
+ end
21
+ end
22
+
23
+ refine FalseClass do
24
+ def blank?
25
+ true
26
+ end
27
+ end
28
+
29
+ refine TrueClass do
30
+ def blank?
31
+ false
32
+ end
33
+ end
34
+
35
+ refine Array do
36
+ alias_method :blank?, :empty?
37
+ end
38
+
39
+ refine Hash do
40
+ alias_method :blank?, :empty?
41
+ end
42
+
43
+ refine String do
44
+ def blank?
45
+ empty? || /\A[[:space:]]*\z/.match?(self)
46
+ end
47
+ end
48
+
49
+ refine Numeric do
50
+ def blank?
51
+ false
52
+ end
53
+ end
54
+
55
+ refine Time do
56
+ def blank?
57
+ false
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,134 @@
1
+ require "csv"
2
+
3
+ module JMACode::PointAmedas
4
+ class Ame < Struct.new(
5
+ :code, :name, :name_phonetic, :type, :government_branch_name, :managed_by,
6
+ :location, :lat, :lng, :altitude, :altitude_anemometer, :altitude_thermometer, :observation_started_since,
7
+ keyword_init: true
8
+ )
9
+ HEADERS = %i(
10
+ government_branch_name
11
+ code
12
+ type
13
+ name
14
+ name_phonetic
15
+ location
16
+ lat_major
17
+ lat_minor
18
+ lng_major
19
+ lng_minor
20
+ altitude
21
+ altitude_anemometer
22
+ altitude_thermometer
23
+ observation_started_since
24
+ memo1
25
+ memo2
26
+ )
27
+
28
+ class << self
29
+ def load_20240325(&block)
30
+ path = File.join(File.dirname(__FILE__), "../../data/20240325_PointAmedas/ame_master.csv")
31
+ File.open(path) do |f|
32
+ csv = CSV.new(f, headers: HEADERS, row_sep: "\r\n")
33
+ if block_given?
34
+ yield(csv)
35
+ else
36
+ load(csv, num_headers: 2, &block)
37
+ end
38
+ end
39
+ end
40
+
41
+ def load(csv, num_headers: 2)
42
+ managed_by = nil
43
+ list = []
44
+ csv.each.with_index do |row, i|
45
+ next if i < num_headers
46
+ branch = row[:government_branch_name]
47
+ if branch && branch.end_with?('管理')
48
+ managed_by = branch
49
+ else
50
+ list << build_by_csv_row(row, managed_by: managed_by)
51
+ end
52
+ end
53
+ list
54
+ end
55
+
56
+ def build_by_csv_row(row, managed_by: nil)
57
+ new(
58
+ code: row[:code],
59
+ name: row[:name],
60
+ name_phonetic: row[:name_phonetic],
61
+ managed_by: managed_by,
62
+ government_branch_name: row[:government_branch_name],
63
+ type: row[:type],
64
+ location: row[:location],
65
+ lat: "#{row[:lat_major]}.#{row[:lat_minor]}".to_f,
66
+ lng: "#{row[:lng_major]}.#{row[:lng_minor]}".to_f,
67
+ altitude: row[:altitude],
68
+ altitude_anemometer: row[:altitude_anemometer],
69
+ altitude_thermometer: row[:altitude_thermometer],
70
+ observation_started_since: row[:observation_started_since],
71
+ )
72
+ end
73
+ end
74
+ end
75
+
76
+ class Snow < Struct.new(
77
+ :code, :name, :name_phonetic, :type, :government_branch_name,
78
+ :location, :lat, :lng, :altitude, :observation_started_since,
79
+ keyword_init: true
80
+ )
81
+ HEADERS = %i(
82
+ government_branch_name
83
+ code
84
+ type
85
+ name
86
+ name_phonetic
87
+ location
88
+ lat_major
89
+ lat_minor
90
+ lng_major
91
+ lng_minor
92
+ altitude
93
+ observation_started_since
94
+ )
95
+
96
+ class << self
97
+ def load_20240325(&block)
98
+ path = File.join(File.dirname(__FILE__), "../../data/20240325_PointAmedas/snow_master.csv")
99
+ File.open(path) do |f|
100
+ csv = CSV.new(f, headers: HEADERS, row_sep: "\r\n")
101
+ if block_given?
102
+ yield(csv)
103
+ else
104
+ load(csv, num_headers: 2, &block)
105
+ end
106
+ end
107
+ end
108
+
109
+ def load(csv, num_headers: 2)
110
+ list = []
111
+ csv.each.with_index do |row, i|
112
+ next if i < num_headers
113
+ list << build_by_csv_row(row)
114
+ end
115
+ list
116
+ end
117
+
118
+ def build_by_csv_row(row)
119
+ new(
120
+ code: row[:code],
121
+ name: row[:name],
122
+ name_phonetic: row[:name_phonetic],
123
+ government_branch_name: row[:government_branch_name],
124
+ type: row[:type],
125
+ location: row[:location],
126
+ lat: "#{row[:lat_major]}.#{row[:lat_minor]}".to_f,
127
+ lng: "#{row[:lng_major]}.#{row[:lng_minor]}".to_f,
128
+ altitude: row[:altitude],
129
+ observation_started_since: row[:observation_started_since],
130
+ )
131
+ end
132
+ end
133
+ end
134
+ end
@@ -0,0 +1,30 @@
1
+ require "csv"
2
+
3
+ module JMACode
4
+ class RiverOffice < Struct.new(
5
+ :code, :name,
6
+ keyword_init: true
7
+ )
8
+ HEADERS = %i(code name)
9
+
10
+ class << self
11
+ def load_20240315(&block)
12
+ path = File.join(File.dirname(__FILE__), "../../data/20240315_RiverOffice.csv")
13
+ File.open(path) do |f|
14
+ csv = CSV.new(f, headers: HEADERS, row_sep: "\r\n")
15
+ if block_given?
16
+ yield(csv)
17
+ else
18
+ load(csv, num_headers: 3, &block)
19
+ end
20
+ end
21
+ end
22
+
23
+ def load(csv, num_headers: 3)
24
+ csv.drop(num_headers).map do |row|
25
+ new(code: row[:code], name: row[:name])
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end