Class: RelatonNist::PubsExport

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/relaton_nist/pubs_export.rb

Constant Summary collapse

DOMAIN =
"https://csrc.nist.gov".freeze
PUBS_EXPORT =
URI.join(DOMAIN, "/CSRC/media/feeds/metanorma/pubs-export")
DATAFILEDIR =
File.expand_path ".relaton/nist", Dir.home
DATAFILE =
File.expand_path "pubs-export.zip", DATAFILEDIR

Instance Method Summary collapse

Constructor Details

#initializePubsExport

Returns a new instance of PubsExport.



10
11
12
# File 'lib/relaton_nist/pubs_export.rb', line 10

def initialize
  @mutex = Mutex.new
end

Instance Method Details

#dataArray<Hash>

Fetches json data form server

Returns:

  • (Array<Hash>)

    json data



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/relaton_nist/pubs_export.rb', line 19

def data
  @mutex.synchronize do
    @data ||= begin
      ctime = File.ctime DATAFILE if File.exist? DATAFILE
      if !ctime || ctime.to_date < Date.today || File.size(DATAFILE).zero?
        fetch_data(ctime)
      end
      unzip
    end
  end
end