Class: WdwSources::TouringplansUpdate

Inherits:
Object
  • Object
show all
Defined in:
app/models/wdw_sources/touringplans_update.rb

Class Method Summary collapse

Class Method Details

._cache_tp_place(tp_list_item_venue_permalink, tp_list_item_permalink, interest) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/models/wdw_sources/touringplans_update.rb', line 26

def self._cache_tp_place(tp_list_item_venue_permalink, tp_list_item_permalink, interest)
  return "Missing tp_list_item_venue_permalink" if tp_list_item_venue_permalink.to_s.length < 3
  return "Missing tp_list_item_permalink" if tp_list_item_permalink.to_s.length < 3
  return "Missing interest" if interest.to_s.length < 3

  cache_resources       = {"attractions" => WdwSources::TouringplansAttraction, 
                           "dining"      => WdwSources::TouringplansDiningVenue,
                           "hotels"      => WdwSources::TouringplansHotel
                          }
                          
  cache_resource        = cache_resources[interest]
  cache_item            = cache_resource.find_or_create_by(permalink: tp_list_item_permalink)

  tp_item_full_record  = Touringplans.show(tp_list_item_venue_permalink,interest, tp_list_item_permalink)

  vp = {venue_permalink: tp_list_item_venue_permalink}
  full_record_hash = vp.merge(tp_item_full_record.to_h)
  cache_item.update!(full_record_hash)
  # tp_item_full_record.to_h
  cache_item
end

.list_all(venue_type) ⇒ Object



5
6
7
# File 'app/models/wdw_sources/touringplans_update.rb', line 5

def self.list_all(venue_type)
  Touringplans.list_all(venue_type)
end

.sync_all(interest) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/models/wdw_sources/touringplans_update.rb', line 9

def self.sync_all(interest)
  
  tp_list = Touringplans.list_all(interest)
  tp_list.each_with_index do |tp_list_item, index|
    numerator   = (index + 1).to_f
    denominator   = tp_list.length.to_f
    percentage    = (numerator / denominator * 100).round(2)

    puts "#{tp_list_item.permalink}  -- #{percentage}% of #{interest.to_s} synced" 

    tp_list_item_venue_permalink = tp_list_item.venue_permalink
    tp_list_item_permalink = tp_list_item.permalink

    _cache_tp_place(tp_list_item_venue_permalink, tp_list_item_permalink, interest)
  end
end