class WhatTheGem::Usage::Extractor::CodeBlock
Public Class Methods
new(body)
click to toggle source
Calls superclass method
# File lib/whatthegem/usage/extractor.rb, line 31 def initialize(body) super(try_sanitize(body)) end
Public Instance Methods
ruby?()
click to toggle source
# File lib/whatthegem/usage/extractor.rb, line 35 def ruby? # Ripper returns nil for anything but correct Ruby # # TODO: Unfortunately, Ripper is fixed to current version syntax, so trying this trick on # Ruby 2.4 with something that uses Ruby 2.7 features will unhelpfully return "no, not Ruby" # # Maybe trying parser gem could lead to the same effect !Ripper.sexp(body).nil? end
service?()
click to toggle source
# File lib/whatthegem/usage/extractor.rb, line 45 def service? body.match?(REMOVE_BLOCKS_RE) end
to_h()
click to toggle source
# File lib/whatthegem/usage/extractor.rb, line 49 def to_h {body: body} end
Private Instance Methods
try_sanitize(text)
click to toggle source
# File lib/whatthegem/usage/extractor.rb, line 55 def try_sanitize(text) text .gsub(/^>> /, '') # Imitating work from IRB, TODO: various IRB/Pry patterns .gsub(/^(=> )/, '# \\1') # Output in IRB, should be hidden as comment .gsub(/^(Results: )/, '# \\1') # Output, in some gems .gsub(/^( *)(\.{2,})/, '\\1# \\2') # "...and so on..." in code examples end