Class: Jekyll::AutoScout24::Entry

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

Overview

A drop in liquid is a class which allows you to export DOM like things to liquid. Methods of drops are callable. The main use for liquid drops is to implement lazy loaded objects. If you would like to make data available to the web designers which you don’t want loaded unless needed then a drop is a great way to do that.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ Entry

ctor



33
34
35
# File 'lib/jekyll-autoscout24/backup_reader.rb', line 33

def initialize(node)
  @node = node
end

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



30
31
32
# File 'lib/jekyll-autoscout24/backup_reader.rb', line 30

def node
  @node
end

Instance Method Details

#liquid_method_missing(name) ⇒ Object

Catch all method to be flexible and adaptable based on the XML structure provided.



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/jekyll-autoscout24/backup_reader.rb', line 38

def liquid_method_missing(name)
  # lookup child node by name
  found = @node.locate(name).first
  # no match or empty node, therefore nil
  return nil if found.nil? || found.nodes.empty?
  # could be an array
  return Prices.new(found) if name == 'prices'
  return Equipments.new(found) if name == 'equipments'
  return Images.new(found) if name == 'images'
  # either text or recurse
  found.text === nil ? Entry.new(found) : found.text
end