Class: RDocF95::RI::Writer

Inherits:
Object
  • Object
show all
Defined in:
lib/rdoc-f95/ri/writer.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_dir) ⇒ Writer

Returns a new instance of Writer.



25
26
27
# File 'lib/rdoc-f95/ri/writer.rb', line 25

def initialize(base_dir)
  @base_dir = base_dir
end

Class Method Details

.class_desc_path(dir, class_desc) ⇒ Object



6
7
8
# File 'lib/rdoc-f95/ri/writer.rb', line 6

def self.class_desc_path(dir, class_desc)
  File.join(dir, "cdesc-" + class_desc.name + ".yaml")
end

.external_to_internal(name) ⇒ Object

And the reverse operation



21
22
23
# File 'lib/rdoc-f95/ri/writer.rb', line 21

def self.external_to_internal(name)
  name.gsub(/%([0-9a-f]{2,2})/) { $1.to_i(16).chr }
end

.internal_to_external(name) ⇒ Object

Convert a name from internal form (containing punctuation) to an external form (where punctuation is replaced by %xx)



14
15
16
# File 'lib/rdoc-f95/ri/writer.rb', line 14

def self.internal_to_external(name)
  name.gsub(/\W/) { "%%%02x" % $&[0].ord }
end

Instance Method Details

#add_class(class_desc) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/rdoc-f95/ri/writer.rb', line 33

def add_class(class_desc)
  dir = path_to_dir(class_desc.full_name)
  FileUtils.mkdir_p(dir)
  class_file_name = self.class.class_desc_path(dir, class_desc)
  File.open(class_file_name, "w") do |f|
    f.write(class_desc.serialize)
  end
end

#add_method(class_desc, method_desc) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/rdoc-f95/ri/writer.rb', line 42

def add_method(class_desc, method_desc)
  dir = path_to_dir(class_desc.full_name)
  file_name = self.class.internal_to_external(method_desc.name)
  meth_file_name = File.join(dir, file_name)
  if method_desc.is_singleton
    meth_file_name += "-c.yaml"
  else
    meth_file_name += "-i.yaml"
  end

  File.open(meth_file_name, "w") do |f|
    f.write(method_desc.serialize)
  end
end

#remove_class(class_desc) ⇒ Object



29
30
31
# File 'lib/rdoc-f95/ri/writer.rb', line 29

def remove_class(class_desc)
  FileUtils.rm_rf(path_to_dir(class_desc.full_name))
end