class Reference

Public Class Methods

new() click to toggle source

Constructors and Destructors

# File lib/refs/References.rb, line 14
def initialize
  load_list
end

Public Instance Methods

acronym_list() click to toggle source

Accessors

# File lib/refs/References.rb, line 22
def acronym_list
  @acronym_list
end
load_list() click to toggle source

Load

# File lib/refs/References.rb, line 86
def load_list
  
  # Save the physical location of the reference directory
  @root = Dir.pwd + "/ref"
  
  # Load the list of acronyms
  @acronym_filename = @root + "/acronyms.yaml"
  if File.exists?(@acronym_filename) then
    @acronym_list = YAML.load_file(@acronym_filename)
  else
    @acronym_list = Hash.new
  end
      
end
save_list() click to toggle source

Save

# File lib/refs/References.rb, line 66
def save_list

  # Save the document list
  
  ##
  ## Save the list of acronyms
  ##
  
  # Does the file path exist
  unless Dir.exists?(File.dirname(@acronym_filename)) then
    FileUtils.mkdir_p(File.dirname(@acronym_filename))
  end
  
  File.open(@acronym_filename, 'w') do |out|
    YAML.dump(@acronym_list, out)
  end
  
end
update(syntax_tree) click to toggle source

Update methods. Used once we have all the data, but before we do any generating, to make sure everything is up-to-date

# File lib/refs/References.rb, line 31
def update(syntax_tree)
  # Update the document list
  
  # Walk the forest, looking for targets at the paragraph
  # level
  syntax_tree.block_forest.each{|tree|
    #walker.walk_tree(tree)
    #puts tree.content.target
    
    tree.each{|node|
      # Look for interesting nodes
      case node.content.type
        when :ac
          # Can we find this in the list of acronyms?
          unless @acronym_list.include?(node.content.content) then
            acronym = Hash.new
            acronym['text'] = node.content.content
            
            @acronym_list[node.content.content] = acronym
          end
      end
    }
  }
  
  # Save the updates
  save_list

end