Class: Sweetie::Conversion
- Inherits:
-
Object
- Object
- Sweetie::Conversion
- Includes:
- Helper
- Defined in:
- lib/sweetie/conversion.rb
Overview
The class which can get the stati of the project including number of html pages, images, and links
Instance Method Summary collapse
-
#build_time ⇒ String
Create the actual build time.
-
#count_all_html_pages(dir) ⇒ Integer
Counts all html pages for the given directory.
-
#count_all_images(dir) ⇒ Integer
Counts all the images for the given directory.
-
#count_all_links(dir) ⇒ Integer
Counts all the links for the given directory.
-
#count_images_of_one_page(page) ⇒ Integer
Count the images of one html page.
-
#count_link_of_one_page(page) ⇒ Integer
Counts the link of on html page.
-
#create_stati ⇒ nil
It saves the gathered information about the build-date, the links, the images, and the number of html-pages in the jekyll project.
-
#initialize(dir = '_site', config = '_config.yml') ⇒ nil
constructor
A basic initialize method.
Methods included from Helper
#check_directory_and_config_file, #harvest, #output_count, #perform_global_search, #perform_search_for_single_page, #traverse, #write_config
Constructor Details
#initialize(dir = '_site', config = '_config.yml') ⇒ nil
A basic initialize method.
14 15 16 17 |
# File 'lib/sweetie/conversion.rb', line 14 def initialize(dir = '_site', config = '_config.yml') @dir = dir @config = config end |
Instance Method Details
#build_time ⇒ String
Create the actual build time.
106 107 108 109 |
# File 'lib/sweetie/conversion.rb', line 106 def build_time time = Time.now "#{time.month}-#{time.day}-#{time.year}" end |
#count_all_html_pages(dir) ⇒ Integer
Counts all html pages for the given directory.
83 84 85 |
# File 'lib/sweetie/conversion.rb', line 83 def count_all_html_pages(dir) perform_global_search('//html', [], dir) end |
#count_all_images(dir) ⇒ Integer
Counts all the images for the given directory.
99 100 101 |
# File 'lib/sweetie/conversion.rb', line 99 def count_all_images(dir) perform_global_search('//img', [], dir) end |
#count_all_links(dir) ⇒ Integer
Counts all the links for the given directory.
91 92 93 |
# File 'lib/sweetie/conversion.rb', line 91 def count_all_links(dir) perform_global_search('//a', [], dir) end |
#count_images_of_one_page(page) ⇒ Integer
Count the images of one html page.
75 76 77 |
# File 'lib/sweetie/conversion.rb', line 75 def count_images_of_one_page(page) perform_search_for_single_page('//img', [], page) end |
#count_link_of_one_page(page) ⇒ Integer
Counts the link of on html page.
67 68 69 |
# File 'lib/sweetie/conversion.rb', line 67 def count_link_of_one_page(page) perform_search_for_single_page('//a', [], page) end |
#create_stati ⇒ nil
It saves the gathered information about the build-date, the links, the images, and the number of html-pages in the jekyll project.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/sweetie/conversion.rb', line 23 def create_stati check_directory_and_config_file(@dir, @config) file = File.open(@config) text = '' if File.extname(file) =~ /.rb/ while line = file.gets text << if line =~ /set :build,/ "set :build, '#{build_time}'\n" elsif line =~ /set :htmlpages,/ "set :htmlpages, #{count_all_html_pages(@dir)}\n" elsif line =~ /set :images,/ "set :images, #{count_all_images(@dir)}\n" elsif line =~ /set :links,/ "set :links, #{count_all_links(@dir)}\n" else line end end else while line = file.gets text << if line =~ /build:/ "build: '#{build_time}'\n" elsif line =~ /htmlpages:/ "htmlpages: #{count_all_html_pages(@dir)}\n" elsif line =~ /images:/ "images: #{count_all_images(@dir)}\n" elsif line =~ /links:/ "links: #{count_all_links(@dir)}\n" else line end end end file.close write_config(file, text) end |