Class: Sweetie::Conversion

Inherits:
Object
  • Object
show all
Extended by:
Helper
Defined in:
lib/sweetie/conversion.rb

Constant Summary collapse

@@config =
"_config.yml"
@@dir =
"_site"

Class Method Summary collapse

Methods included from Helper

check_config_and_directory_file, harvest, output_count, perform_global_search, perform_search_for_single_page, traverse, write_config

Class Method Details

.build_timeString

Create the actual build time

Returns:

  • (String)

    in the date format mm-dd-yyyy



77
78
79
80
# File 'lib/sweetie/conversion.rb', line 77

def build_time
  time = Time.now
  "#{time.month}-#{time.day}-#{time.year}"
end

.conversionObject

Opens the config file and search after the specified parameters. It saves the gathered information about the build-date, the links, the images, and the number of html-pages in the jekyll project.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/sweetie/conversion.rb', line 17

def conversion
  check_config_and_directory_file(@@config, @@dir)

  file = File.open(@@config)
  text = ""
  while line = file.gets
    if line.match(/build:/)
      text << "build: #{build_time}\n"
    elsif line.match(/htmlpages:/)
      text << "htmlpages: #{count_all_html_pages(@@dir)}\n"
    elsif line.match(/images:/)
      text << "images: #{count_all_images(@@dir)}\n"
    elsif line.match(/links:/)
      text << "links: #{count_all_links(@@dir)}\n"
    else
      text << line
    end
  end
  file.close

  write_config(file, text)
end

.count_all_html_pages(dir) ⇒ Fixnum

Counts all html pages

Parameters:

  • the (Dir)

    path of the directory

Returns:

  • (Fixnum)

    the number of unique html pages



57
58
59
# File 'lib/sweetie/conversion.rb', line 57

def count_all_html_pages(dir)
  perform_global_search('//html', [], dir)
end

.count_all_images(dir) ⇒ Object

Counts all the images of all html pages



71
72
73
# File 'lib/sweetie/conversion.rb', line 71

def count_all_images(dir)
  perform_global_search('//img', [], dir)
end

Counts all the links of all html pages



64
65
66
# File 'lib/sweetie/conversion.rb', line 64

def count_all_links(dir)
  perform_global_search('//a', [], dir)
end

.count_images_of_one_page(page) ⇒ Object

Count the images of one html page

Returns:

  • the number of unique images



50
51
52
# File 'lib/sweetie/conversion.rb', line 50

def count_images_of_one_page(page)
  perform_search_for_single_page('//img', [], page)
end

Counts the link of on html page

Parameters:

  • the (page)

    path of a html page

Returns:

  • the number of unique links



43
44
45
# File 'lib/sweetie/conversion.rb', line 43

def count_link_of_one_page(page)
  perform_search_for_single_page('//a', [], page)
end