2015-04-27 21:26:37 +02:00
|
|
|
require 'elasticsearch/model'
|
2015-04-27 21:03:58 +02:00
|
|
|
require 'json'
|
2015-04-13 22:09:28 +02:00
|
|
|
|
|
|
|
class Paper < ActiveRecord::Base
|
2015-04-27 21:26:37 +02:00
|
|
|
include Elasticsearch::Model
|
|
|
|
include Elasticsearch::Model::Callbacks
|
|
|
|
|
2015-04-13 22:09:28 +02:00
|
|
|
class << self
|
2015-04-27 21:03:58 +02:00
|
|
|
def import_from_json(json_string)
|
|
|
|
JSON.parse(json_string).each do |record|
|
2015-04-13 22:09:28 +02:00
|
|
|
attributes = {
|
2015-04-27 21:03:58 +02:00
|
|
|
name: record['name'],
|
|
|
|
url: record['url'],
|
|
|
|
reference: record['reference'],
|
|
|
|
paper_type: record['paper_type'],
|
|
|
|
originator: record['originator'],
|
|
|
|
published_at: record['published_at'],
|
2015-04-13 22:09:28 +02:00
|
|
|
}
|
|
|
|
create!(attributes)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|