lib/daigaku/markdown/ruby_doc.rb in daigaku-0.2.0 vs lib/daigaku/markdown/ruby_doc.rb in daigaku-0.3.0
- old
+ new
@@ -41,23 +41,23 @@
result.sub!(doc_regex(:stdlib, capture), stdlib_link(capture))
end
end
def doc_regex(type, capture)
- /\(ruby-doc #{type}: #{capture}\)/
+ Regexp.new(Regexp.escape("(ruby-doc #{type}: #{capture})"))
end
def core_link(text)
constants = ruby_constants(text).join('/')
- method = ruby_method(text)
+ method = ruby_method(text)
"#{CORE_BASE_URL}/#{constants}.html#{method}"
end
def stdlib_link(text)
- constants = ruby_constants(text).join('/')
- method = ruby_method(text)
+ constants = ruby_constants(text).join('/')
+ method = ruby_method(text)
libdoc_part = "libdoc/#{ruby_stdlib(text)}/rdoc"
"#{STDLIB_BASE_URL}/#{libdoc_part}/#{constants}.html#{method}"
end
@@ -66,21 +66,21 @@
# (ruby-doc stdlib: net/http Net::HTTP) => 'net/http'
# then this lib name is used.
# Else the lib is created from the constants, e.g.
# (ruby-doc stdlib: Time) => 'time'
def ruby_stdlib(text)
- parts = text.split(' ')
+ parts = text.split
if parts.length > 1
parts.first.strip.downcase
else
ruby_constants(text).join('/').downcase
end
end
def ruby_constants(text)
- parts = text.split(' ').last.split(/::|#/)
+ parts = text.split.last.split(/::|#/)
select_capitalized(parts)
end
def ruby_method(text)
method = text.split(/::|#/).last
@@ -90,10 +90,12 @@
method_name = CGI.escape(method.strip).gsub('%', '-').gsub(/\A-/, '')
"#method-#{method_type}-#{method_name}"
end
def select_capitalized(parts)
- parts.select { |part| part[0] == part[0].upcase }
+ parts.select do |part|
+ part[0].match(/\w/) && part[0] == part[0].upcase
+ end
end
def downcased?(text)
text == text.downcase
end