class DocuBot::Glossary
Attributes
bundle[RW]
entries[RW]
Public Class Methods
new( bundle, dir )
click to toggle source
# File lib/docubot/glossary.rb, line 4 def initialize( bundle, dir ) @entries = {} @downcased = {} @bundle = bundle @missing = Hash.new{ |h,k| h[k]=[] } # .directory? also ensures that the path exists if File.directory?( dir ) @directory = File.expand_path( dir ) # Dir[ dir/'*' ].each do |item| # page = DocuBot::Page.new( @bundle, item ) # self << page # end end end
Public Instance Methods
<<( page )
click to toggle source
# File lib/docubot/glossary.rb, line 39 def <<( page ) self[ page.title ] = page end
[]( term )
click to toggle source
# File lib/docubot/glossary.rb, line 23 def []( term ) @entries[ @downcased[ term.downcase ] ] end
[]=( term, definition )
click to toggle source
# File lib/docubot/glossary.rb, line 18 def []=( term, definition ) @entries[ term ] = definition @downcased[ term.downcase ] = term @missing.delete( term.downcase ) end
each() { |term, page| ... }
click to toggle source
# File lib/docubot/glossary.rb, line 33 def each @entries.each{ |term,page| yield term, page } end
inspect()
click to toggle source
# File lib/docubot/glossary.rb, line 49 def inspect "<#{self.class} terms='#{@entries.keys.join ', '}'>" end
missing_terms()
click to toggle source
# File lib/docubot/glossary.rb, line 36 def missing_terms @missing end
term_used( term, referring_page )
click to toggle source
# File lib/docubot/glossary.rb, line 26 def term_used( term, referring_page ) down = term.downcase unless @downcased[down] @missing[down] << referring_page @missing[down].uniq! end end
to_js()
click to toggle source
# File lib/docubot/glossary.rb, line 42 def to_js "$glossaryTerms = {#{ @entries.reject{ |term,page| page.hide }.map do |term,page| "'#{term.downcase.gsub("'","\\\\'")}':'#{page.to_html.gsub("'","\\\\'").gsub(/[\r\n]/,'\\n')}'" end.join(",\n") }};" end