Class: HTML2Index
- Inherits:
-
Object
- Object
- HTML2Index
- Includes:
- BasicLogging, Nokogiri
- Defined in:
- lib/html2index.rb
Constant Summary collapse
- @@log_level =
:debug
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 BasicLogging
#clear_log, is_muted?, #level, #log, mute, #set_level, #set_target, #target
Constructor Details
#initialize(*argv) ⇒ HTML2Index
initialize the HTML2Index-object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/html2index.rb', line 40 def initialize(*argv) # ensure the configuration-file exist. = ArgParser.parse(argv) $configuration = Configuration.new() $configuration.user_conf set_level $log_level @file = $configuration.source debug("read #{@file}, write #{$configuration.target}") msg = '' [:exist?, :readable?, :file?].each do |cond| if !File.send(cond, @file) error("Error: unsuitable file " <<@file << ": NOT " << cond.to_s.split('?')[0] << '!') exit false end end ftype = Marcel::Magic.by_path(@file).subtype debug('ftype for ' << @file << ' is ' << ftype.to_s) if(ftype && !ftype.empty? && !ftype.downcase.match(/(html|xml)/) ) error(@file.dup << ' does not look like a valid file to scan: ' << ftype) exit false end @problem_log = File.join(temp_dir, PROBLEM_LOG) debug('calling generate() ') generate() end |
Instance Method Details
#dict_list ⇒ Object
create an unnumbered list of the consulted dictionaries.
71 72 73 74 75 76 77 78 |
# File 'lib/html2index.rb', line 71 def dict_list list = '<ul>' $configuration.dicts.each do |d| list << '<li>' << d.name << ' : ' << '<a href="' << d.url << '">' << d.url << '</a></li>' << "\n" end debug('list is ' << list.to_s) list << "</ul>\n" end |
#generate ⇒ Object
Parses the html-file and generates the glossary.
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/html2index.rb', line 83 def generate() info('Generating... PSE wait') begin @doc = HTML::Document.parse(File.open(@file ) ) write_html() rescue SystemExit => ir info "Bye" exit true rescue Exception => ex error "line #{__LINE__}: " << ex. exit false end if(File.exist?(@problem_log )) info "Some expressions caused problems and are listed in " << @problem_log end end |