Class: G5IntegrationsUpdatable::FeedProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/g5_integrations_updatable/feed_processor.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ FeedProcessor

Returns a new instance of FeedProcessor.



5
6
7
# File 'lib/g5_integrations_updatable/feed_processor.rb', line 5

def initialize(params={})
  self.feed_url = params[:feed_url]
end

Instance Attribute Details

#feed_urlObject

Returns the value of attribute feed_url.



3
4
5
# File 'lib/g5_integrations_updatable/feed_processor.rb', line 3

def feed_url
  @feed_url
end

Class Method Details

.destroy_existing(feed_array) ⇒ Object



18
19
20
21
# File 'lib/g5_integrations_updatable/feed_processor.rb', line 18

def destroy_existing(feed_array)
  existing = G5IntegrationsUpdatable::LocationSetting.where(client_urn: feed_array.collect { |feed| feed['client_urn'] })
  existing.destroy_all
end

.find_or_create_all(feed_array) ⇒ Object



23
24
25
26
27
# File 'lib/g5_integrations_updatable/feed_processor.rb', line 23

def find_or_create_all(feed_array)
  feed_array.each do |location_setting_hash|
    G5IntegrationsUpdatable::LocationSetting.find_or_create_from_feed(location_setting_hash)
  end
end

.load_all_settings(all_uri) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/g5_integrations_updatable/feed_processor.rb', line 10

def load_all_settings(all_uri)
  result_hash = G5IntegrationsUpdatable::FeedFetcher.new(all_uri).process
  G5IntegrationsUpdatable::LocationSetting.transaction do
    destroy_existing result_hash
    find_or_create_all result_hash
  end
end

Instance Method Details

#processObject



30
31
32
# File 'lib/g5_integrations_updatable/feed_processor.rb', line 30

def process
  self.class.find_or_create_all feed_hash_array
end