Class: XmlFilesDatasource

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/rotating_es_loader/xml_files_datasource.rb

Overview

:nodoc

Instance Method Summary collapse

Constructor Details

#initialize(glob) ⇒ XmlFilesDatasource

Returns a new instance of XmlFilesDatasource.



9
10
11
# File 'lib/rotating_es_loader/xml_files_datasource.rb', line 9

def initialize(glob)
  @files = Dir.glob(glob).to_a
end

Instance Method Details

#each(&block) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rotating_es_loader/xml_files_datasource.rb', line 17

def each(&block)
  return to_enum(:each) unless block

  @files.each do |xml_file|
    hash = XmlSimple.xml_in(
      xml_file,
      ForceArray: false,
      SuppressEmpty: ''
    )
    Array(normalize(hash)).each(&block)
  end
  
  self
end

#normalize(o) ⇒ Object



13
14
15
# File 'lib/rotating_es_loader/xml_files_datasource.rb', line 13

def normalize(o)
  o
end

#sizeObject



32
33
34
# File 'lib/rotating_es_loader/xml_files_datasource.rb', line 32

def size
  @files.size
end