geo_master_jp 0.1.26 → 0.1.28

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 222479be95afab1d7dfa5087907f5a99dcf229a4c35090c0b2dc8ba0fad79ac6
4
- data.tar.gz: 9e7a0dfd2ace7c18dc608d2255cf2a6e50b9198a0f1d981865d650ac479674a5
3
+ metadata.gz: adc8a7e422e37711056c4ddd7712130b61589a1c195b37523dc3d724ffd8a5e9
4
+ data.tar.gz: ed1f046133cf53560bf063eac7077da0e10e6d48673824c54bcef2e37af54211
5
5
  SHA512:
6
- metadata.gz: 3a77f5add500810b1e8c5af4645e72f5a420b1a9f2cf2e92682ebbd7636f327b87833c01ae4174e62a9a9efc48d1c7670426bc0bc71ec7e54b88c128f3dad423
7
- data.tar.gz: 67e6b73dad5918e49cc8f92889471cbd3521ff7a60e3fa4980fbc9c5a97b7b89d1e4b2911e68b8e7efcda75a3e0081aa6edbd5c04aea6a5c87bfc501a424f813
6
+ metadata.gz: ccd1b651a6d72e10c34d9224fc700d549efd350df4a7b091b4adaea5be7fbc39d37b0ea4b80e2ea21e82f669db158fa089b2b2fe6585e80e68608d6d1a438b71
7
+ data.tar.gz: 5ea2374908c016d0ad9709075263889b580e889503d29e924ef8a5a58aea4ebd3da63695a1d10e3afe29d54e1ff79567330a50f2098a2bbf710527e241399f0e
@@ -3,11 +3,13 @@ module GeoMasterJp
3
3
  def prefectures
4
4
  prefectures = GeoMasterJp::Prefecture.all
5
5
 
6
+ prefectures = GeoMasterJp.config.api.prefectures_filter.call(prefectures) if GeoMasterJp.config.api.prefectures_filter
7
+
6
8
  render json: {
7
9
  prefectures: prefectures.map{|prefecture|
8
10
  prefecture.as_json(only: [:code, :name, :name_kana, :name_alphabet, :short_name])
9
11
  },
10
- initials: prefectures.group_by(&:head_kana).sort_by(&:first).to_h
12
+ initials: prefectures.sort_by(&:name_kana).group_by(&:head_kana).sort_by(&:first).to_h
11
13
  }
12
14
  end
13
15
 
@@ -20,11 +22,13 @@ module GeoMasterJp
20
22
 
21
23
  cities = GeoMasterJp::Prefecture.find_by(code: params[:prefecture_code]).cities
22
24
 
25
+ cities = GeoMasterJp.config.api.cities_filter.call(cities) if GeoMasterJp.config.api.cities_filter
26
+
23
27
  render json: {
24
28
  cities: cities.map{|city|
25
29
  city.as_json(only: [:code, :name, :name_kana, :name_alphabet, :short_name])
26
30
  },
27
- initials: cities.group_by(&:head_kana).sort_by(&:first).to_h
31
+ initials: cities.sort_by(&:name_kana).group_by(&:head_kana).sort_by(&:first).to_h
28
32
  }
29
33
  end
30
34
 
@@ -37,12 +41,18 @@ module GeoMasterJp
37
41
 
38
42
  towns = GeoMasterJp::City.find_by(code: params[:city_code]).towns
39
43
 
44
+ towns = GeoMasterJp.config.api.towns_filter.call(towns) if GeoMasterJp.config.api.towns_filter
45
+
40
46
  render json: {
41
47
  towns: towns.map{|town|
42
48
  town.as_json(only: [:zip_code, :code, :name, :name_kana, :name_alphabet, :short_name])
43
49
  },
44
- initials: towns.group_by(&:head_kana).sort_by(&:first).to_h
50
+ initials: towns.sort_by(&:name_kana).group_by(&:head_kana).sort_by(&:first).to_h
45
51
  }
46
52
  end
53
+
54
+ def self.aaa(text)
55
+ puts text
56
+ end
47
57
  end
48
58
  end
@@ -22,8 +22,8 @@ module GeoMasterJp
22
22
  self.cities.map{|city| [city.name, city.code] }
23
23
  end
24
24
 
25
- def self.select_options
26
- self.all.map{|prefecture| [prefecture.name, prefecture.code] }
25
+ def self.select_options(transactions=nil)
26
+ (transactions || all).map{|prefecture| [prefecture.name, prefecture.code] }
27
27
  end
28
28
  end
29
29
  end
@@ -12,4 +12,14 @@ GeoMasterJp.configure do |config|
12
12
 
13
13
  # Use Models
14
14
  # config.use_models = [:area, :railway]
15
+
16
+ # API Filters
17
+ # config.api.prefectures_filter = ->(prefectures) {
18
+ # prefecture_codes = ['11', '12', '13', '14']
19
+ # prefectures.select { |prefecture| prefecture.code.in?(prefecture_codes) }
20
+ # }
21
+ # config.api.cities_filter = ->(cities) {
22
+ # }
23
+ # config.api.towns_filter = ->(towns) {
24
+ # }
15
25
  end
@@ -9,15 +9,20 @@ module GeoMasterJp
9
9
 
10
10
  class Config
11
11
  # Variables detail is writen in lib/generators/templates/geo_master_jp.rb.
12
- attr_accessor :alternative_class_names, :use_models
12
+ attr_accessor :alternative_class_names, :use_models, :api
13
13
 
14
14
  def initialize
15
15
  @alternative_class_names = {}
16
16
  @use_models = [:area, :railway]
17
+ @api = API.new
17
18
  end
18
19
 
19
20
  def alternative_class_name(key)
20
21
  @alternative_class_names[key] || "GeoMasterJp::#{key.to_s.camelize}"
21
22
  end
23
+
24
+ class API
25
+ attr_accessor :prefectures_filter, :cities_filter, :towns_filter
26
+ end
22
27
  end
23
28
  end
@@ -1,3 +1,3 @@
1
1
  module GeoMasterJp
2
- VERSION = '0.1.26'
2
+ VERSION = '0.1.28'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geo_master_jp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.26
4
+ version: 0.1.28
5
5
  platform: ruby
6
6
  authors:
7
7
  - ykogure
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-29 00:00:00.000000000 Z
11
+ date: 2023-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails