Class: Reference

Inherits:
Object
  • Object
show all
Defined in:
lib/refs/References.rb

Instance Method Summary collapse

Constructor Details

#initializeReference

Constructors and Destructors



14
15
16
# File 'lib/refs/References.rb', line 14

def initialize
  load_list
end

Instance Method Details

#acronym_listObject

Accessors



22
23
24
# File 'lib/refs/References.rb', line 22

def acronym_list
  @acronym_list
end

#load_listObject

Load



86
87
88
89
90
91
92
93
94
95
96
97
98
99
# 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_listObject

Save



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# 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) ⇒ Object

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



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# 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