# File doc/language/mrbdoc/lib/mrbdoc_analyze.rb, line 5
def analyze_code dir, &block
@mrb_files = {}
@dir = File.expand_path(dir)
block.call "MRBDOC\tanalyze #{@dir}"
analyze(dir) do |progress|
block.call progress
end
end
# File doc/language/mrbdoc/lib/mrbdoc_analyze.rb, line 16
def each_file(&block); @mrb_files.each {|k,v| block.call k,v}; end
# File doc/language/mrbdoc/lib/mrbdoc_analyze.rb, line 26
def find_c_file(rb_obj_name, c_func_name)
last_file_name_match = ''
each_file do |file_name, file|
c_func = file.c_funcs(c_func_name)
if c_func and file.rb_class(rb_obj_name) or file.rb_module(rb_obj_name)
return file_name
elsif c_func
last_file_name_match = file_name
end
end
last_file_name_match
end
# File doc/language/mrbdoc/lib/mrbdoc_analyze.rb, line 39
def find_c_file_by_class(name)
each_file do |file_name, file|
rb_class = file.rb_class(name)
return file_name unless rb_class.nil?
end
'nil'
end
# File doc/language/mrbdoc/lib/mrbdoc_analyze.rb, line 47
def find_c_file_by_module(name)
each_file do |file_name, file|
rb_module = file.rb_module(name)
return file_name unless rb_module.nil?
end
'nil'
end
# File doc/language/mrbdoc/lib/mrbdoc_analyze.rb, line 57
def analyze dir, &block
collect_all_files dir, &block
end
# File doc/language/mrbdoc/lib/mrbdoc_analyze.rb, line 61
def collect_all_files dir, &block
l = lambda {|f| block.call " - #{f.name}"}
collect_files(src_code_dir(dir), /\.c$/, &l)
collect_files(mrb_code_dir(dir), /\.rb$/, &l)
end
# File doc/language/mrbdoc/lib/mrbdoc_analyze.rb, line 67
def collect_files dir, rxp, &block
Dir.foreach(dir) do |file|
next unless file =~ rxp
file_path = "#{dir}/#{file}"
mrb_file = MRBFile.new "#{file_path}"
@mrb_files["#{file_path}"] = mrb_file
block.call mrb_file
end
end
# File doc/language/mrbdoc/lib/mrbdoc_docu.rb, line 19
def get_core_list id
core_list = {}
each_file do |file_path, mrb_file|
mrb_file.send(id) do |name, cls_hsh|
core_list[name] = {:data => cls_hsh, :methods => {}, :class_methods => {}}
mrb_file.each_method name do |met_name, met_hsh|
core_list[name][:methods][met_name] = met_hsh
end
mrb_file.each_class_method name do |met_name, met_hsh|
core_list[name][:class_methods][met_name] = met_hsh
end
end
end
core_list
end
# File doc/language/mrbdoc/lib/mrbdoc_analyze.rb, line 80
def mrb_code_dir dir; File.expand_path MRBLIB_DIR, dir; end
# File doc/language/mrbdoc/lib/mrbdoc_docu.rb, line 89
def print_class_methods(io, hsh, cfg)
return unless hsh[:class_methods].size > 0
io.puts "### Class Methods\n\n"
hsh[:class_methods].sort.each do |met_name, met_hsh|
print_method(io, met_name, met_hsh, cfg)
end
end
# File doc/language/mrbdoc/lib/mrbdoc_docu.rb, line 35
def print_core_classes(io, cfg)
core_list = get_core_list :each_class
io.puts "# Core Classes\n\n"
core_list.sort.each do |name, hsh|
file = find_c_file_by_class(name)
file = file.split("#{@dir}/")[1]
iso = hsh[:data][:iso]
iso = 'n/a' if iso.nil? or iso == ''
mixins = hsh[:data][:include].join(', ') unless hsh[:data][:include].nil?
mixins = 'n/a' if mixins.nil? or mixins == ''
io.puts <<CLASS
## #{name}
ISO Code | Mixins | Source File
--- | --- | ---
#{iso} | #{mixins} | #{file}
CLASS
print_class_methods(io, hsh, cfg)
print_methods(io, hsh, cfg)
end
end
# File doc/language/mrbdoc/lib/mrbdoc_docu.rb, line 59
def print_core_modules(io, cfg)
core_list = get_core_list :each_module
io.puts "# Core Modules\n\n"
core_list.sort.each do |name, hsh|
file = find_c_file_by_module(name)
file = file.split("#{@dir}/")[1]
iso = hsh[:data][:iso]
iso = 'n/a' if iso.nil? or iso == ''
io.puts <<CLASS
## #{name}
ISO Code | Source File
--- | ---
#{iso} | #{file}
CLASS
print_class_methods(io, hsh, cfg)
print_methods(io, hsh, cfg)
end
end
# File doc/language/mrbdoc/lib/mrbdoc_docu.rb, line 97
def print_method(io, met_name, met_hsh, cfg)
if cfg[:print_line_no]
line_no_head = ' | Line'
line_no = " | #{find_c_func(met_hsh[:c_func])[:line_no]}"
else
line_no, line_no_head = '', ''
end
file = find_c_file(met_hsh[:rb_class], met_hsh[:c_func])
file = file.split("#{@dir}/")[1]
iso = met_hsh[:iso]
iso = 'n/a' if iso.nil? or iso == ''
io.puts <<METHOD
#### #{met_name}
ISO Code | Source File | C Function#{line_no_head}
--- | --- | ---
#{iso} | #{file} | #{met_hsh[:c_func]}#{line_no}
METHOD
end
# File doc/language/mrbdoc/lib/mrbdoc_docu.rb, line 81
def print_methods(io, hsh, cfg)
return unless hsh[:methods].size > 0
io.puts "### Methods\n\n"
hsh[:methods].sort.each do |met_name, met_hsh|
print_method(io, met_name, met_hsh, cfg)
end
end
Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.
If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.
If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.
If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.