Class: HTML2Index
- Inherits:
-
Object
- Object
- HTML2Index
- Includes:
- Logging, Nokogiri
- Defined in:
- lib/html2index.rb
Instance Method Summary collapse
-
#dict_list ⇒ Object
create an unnumbered list of the consulted dictionaries.
-
#generate ⇒ Object
Parses the html-file and generates the glossary.
-
#initialize(*argv) ⇒ HTML2Index
constructor
initialize the HTML2Index-object.
Methods included from Logging
#debout, #formatter, #init_logger, #log_level=, #log_level?, #log_target=
Constructor Details
#initialize(*argv) ⇒ HTML2Index
initialize the HTML2Index-object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/html2index.rb', line 46 def initialize(*argv) init_logger() # ensure the configuration-file exist. = ArgParser.parse(argv) $configuration = Configuration.new() $configuration.user_conf @log.level = $log_level @file = $configuration.source @log.debug("read #{@file}, write #{$configuration.target}") msg = File_Checking::file_check(@file, :exist?, :readable?, :file?) if(msg) @log.error("Error: unsuitable file " <<@file << ": " << msg) exit false end ftype = File_Checking::file_type(@file) @log.debug('ftype for ' << @file << ' is ' << ftype.to_s) if(ftype && !ftype.empty? && !ftype[0].downcase.match("(html|xml) .*document") ) @log.error(@file.dup << ' does not look like a valid file to scan: ' << ftype) exit false end @problem_log = File.join(temp_dir, PROBLEM_LOG) @log.debug('calling generate() ') generate() end |
Instance Method Details
#dict_list ⇒ Object
create an unnumbered list of the consulted dictionaries.
75 76 77 78 79 80 81 82 |
# File 'lib/html2index.rb', line 75 def dict_list list = '<ul>' $configuration.dicts.each do |d| list << '<li>' << d.name << ' : ' << '<a href="' << d.url << '">' << d.url << '</a></li>' << "\n" end @log.debug('list is ' << list.to_s) list << "</ul>\n" end |
#generate ⇒ Object
Parses the html-file and generates the glossary.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/html2index.rb', line 87 def generate() @log.info('Generating... PSE wait') begin @doc = HTML::Document.parse(File.open(@file ) ) write_html() rescue SystemExit => ir @log.info "Bye" exit true rescue Exception => ex @log.error "line #{__LINE__}: " << ex. exit false end if(File.exist?(@problem_log )) @log.info "Some expressions caused problems and are listed in " << @problem_log end end |