class Jekyll::AutoScout24::BackupReader

Attributes

content[R]
site[R]

Public Class Methods

new(site) click to toggle source

ctor

# File lib/jekyll-autoscout24/backup_reader.rb, line 8
def initialize(site)
  @site = site
end

Public Instance Methods

read!(dir) click to toggle source
# File lib/jekyll-autoscout24/backup_reader.rb, line 12
def read!(dir)
  # Load XML data from the backup file
  backup = Ox.load_file("#{dir}/autoscout24.xml")
  # Locate all vehicle nodes in the backup document
  vehicles, nodes = [], backup.locate('stx3/vehicle_data/vehicles/vehicle')
  # Transform each node found into an instance of Entry drop
  nodes.each { |n| vehicles << Entry.new(n) }
  # Merge current site data with the list of vehicles from the backup
  @site.data.merge!('autoscout24' => vehicles) unless vehicles.empty?
end