Class: SitemapGen::Csv

Inherits:
Object
  • Object
show all
Defined in:
lib/sitemap_gen/csv.rb

Constant Summary collapse

IGNORE_DIRS_REGEX =
/img|cgi-bin|images|css|js/i

Instance Method Summary collapse

Constructor Details

#initialize(dir_path, base_url, save_path) ⇒ Csv

Returns a new instance of Csv.



5
6
7
8
9
10
11
12
13
# File 'lib/sitemap_gen/csv.rb', line 5

def initialize(dir_path, base_url, save_path)
  @dir_path = dir_path
  @base_url = base_url
  @save_path = save_path || Dir.pwd
  @max_level = 1
  @html_files = Dir.glob("#{dir_path}/**/index.html").sort_by { |f| File.dirname(f) }
  raise 'There is no index.html files in your directory' if @html_files.empty?
  @sitemaps = create_sitemaps
end

Instance Method Details

#generateObject



15
16
17
18
19
20
# File 'lib/sitemap_gen/csv.rb', line 15

def generate
  CSV.open("#{@save_path}/sitemap.csv", 'wb') do |csv|
    csv << csv_header
    @sitemaps.each_with_index { |item, i| csv << csv_row(item, i) }
  end
end