Skip to content

Commit

Permalink
cache SectionATS.loadDAT(url)
Browse files Browse the repository at this point in the history
  • Loading branch information
JG1VPP committed Jun 13, 2024
1 parent 7518b5e commit 77c7a60
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions conf/rules/ats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ def code()
end

class SectionATS < Section
@@CACHE = {}

def initialize(name, band, mode, hour = 0..23, zdat = nil)
super()
@name = name
Expand Down Expand Up @@ -156,9 +158,12 @@ def result(list)

def loadDAT(url)
return JAUTIL.get('CITY-BASE') if url.nil?
return @@CACHE.fetch(url)if @@CACHE.member?(url)
text = AssetUtil.root.http(URL.new(url), 'SJIS')
text = text.gsub(/^(\w+) +(.+)$/, '\2 \1')
LocalCityBase.read(text.lines[1..-2].join)
text = text.gsub(/^(\w+) +(.+)$/, '\2 \1').lines.drop(1)
base = LocalCityBase.read(text.take(text.size - 1).join)
@@CACHE[url] = base
base
end
end

Expand Down

0 comments on commit 77c7a60

Please sign in to comment.