Class: Jekyll::AutoScout24::BackupReader

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll-autoscout24/backup_reader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site) ⇒ BackupReader

ctor



8
9
10
# File 'lib/jekyll-autoscout24/backup_reader.rb', line 8

def initialize(site)
  @site = site
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



5
6
7
# File 'lib/jekyll-autoscout24/backup_reader.rb', line 5

def content
  @content
end

#siteObject (readonly)

Returns the value of attribute site.



5
6
7
# File 'lib/jekyll-autoscout24/backup_reader.rb', line 5

def site
  @site
end

Instance Method Details

#read!(dir) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# 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