]> git.openstreetmap.org Git - rails.git/blob - lib/osm_community_index/local_chapter.rb
fc87f64d2a8972cae7ae366dfd97acf09a82b8ee
[rails.git] / lib / osm_community_index / local_chapter.rb
1 module OsmCommunityIndex
2   class LocalChapter
3     attr_reader :id, :name, :url
4
5     @localised_chapters = {}
6
7     def initialize(id, name, url)
8       @id = id
9       @name = name
10       @url = url
11     end
12
13     def self.local_chapters_with_locale(locale)
14       @localised_chapters[locale] ||= load_local_chapters(locale)
15     end
16
17     def self.load_local_chapters(locale)
18       community_index = OsmCommunityIndex.community_index
19       localised_strings = OsmCommunityIndex.localised_strings(locale)
20       local_chapters = []
21       community_index["resources"].each do |id, resource|
22         resource.each do |key, value|
23           next unless key == "type" && value == "osm-lc" && id != "OSMF"
24
25           strings = resource["strings"]
26           name = localised_strings.dig(id, "name") || strings["name"] || strings["community"]
27           url = strings["url"]
28           local_chapters.push(LocalChapter.new(id, name, url))
29         end
30       end
31       local_chapters
32     end
33   end
34 end