Class: SitemapGen::Csv
- Inherits:
-
Object
- Object
- SitemapGen::Csv
- Defined in:
- lib/sitemap_gen/csv.rb
Constant Summary collapse
- IGNORE_DIRS_REGEX =
/img|cgi-bin|images|css|js/i
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(dir_path, base_url, save_path) ⇒ Csv
constructor
A new instance of Csv.
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
#generate ⇒ Object
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 |