stadtratmonitor/app/models/paper.rb

24 lines
583 B
Ruby
Raw Normal View History

require 'elasticsearch/model'
require 'json'
2015-04-13 22:09:28 +02:00
class Paper < ActiveRecord::Base
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks
2015-04-13 22:09:28 +02:00
class << self
def import_from_json(json_string)
JSON.parse(json_string).each do |record|
2015-04-13 22:09:28 +02:00
attributes = {
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