Class: Formulary::QHPImporter

Inherits:
Object
  • Object
show all
Defined in:
lib/formulary/qhp_importer.rb

Overview

This class reads QHP data from a list of urls and loads it into a repository

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(urls, repo) ⇒ QHPImporter

Returns a new instance of QHPImporter.



10
11
12
13
# File 'lib/formulary/qhp_importer.rb', line 10

def initialize(urls, repo)
  @urls = urls
  @repo = repo
end

Instance Attribute Details

#repoObject (readonly)

Returns the value of attribute repo.



8
9
10
# File 'lib/formulary/qhp_importer.rb', line 8

def repo
  @repo
end

#urlsObject (readonly)

Returns the value of attribute urls.



8
9
10
# File 'lib/formulary/qhp_importer.rb', line 8

def urls
  @urls
end

Instance Method Details

#importObject



15
16
17
18
19
20
21
# File 'lib/formulary/qhp_importer.rb', line 15

def import
  urls.each do |url|
    qhp_raw_data = HTTParty.get(url, verify: false) # FIXME
    qhp_json.concat(JSON.parse(qhp_raw_data, symbolize_names: true))
  end
  repo.import(qhp_json)
end

#qhp_jsonObject



23
24
25
# File 'lib/formulary/qhp_importer.rb', line 23

def qhp_json
  @qhp_json ||= []
end