mirror of
https://github.com/CodeforLeipzig/stadtratmonitor.git
synced 2024-10-18 23:54:37 +02:00
5ea5aae4b8
Use url as unique identifier during import
24 lines
663 B
Ruby
24 lines
663 B
Ruby
require 'elasticsearch/model'
|
|
require 'json'
|
|
|
|
class Paper < ActiveRecord::Base
|
|
include Elasticsearch::Model
|
|
include Elasticsearch::Model::Callbacks
|
|
|
|
class << self
|
|
def import_from_json(json_string)
|
|
JSON.parse(json_string).each do |record|
|
|
attributes = {
|
|
name: record['name'],
|
|
url: record['url'],
|
|
reference: record['reference'],
|
|
paper_type: record['paper_type'],
|
|
originator: record['originator'],
|
|
published_at: record['published_at'],
|
|
}
|
|
record = find_or_initialize_by(url: attributes[:url])
|
|
record.update_attributes!(attributes)
|
|
end
|
|
end
|
|
end
|
|
end
|