class WhatTheGem::Usage::Extractor

TODO: more robustly ignore “installation” section or just remove gem 'foo' / gem install -> select only “`ruby section from markdown (if they exist)? -> more removal patterns? Like `rake something`

Constants

REMOVE_BLOCKS
REMOVE_BLOCKS_RE

Attributes

file[R]

Public Class Methods

call(file) click to toggle source
# File lib/whatthegem/usage/extractor.rb, line 64
def self.call(file)
  new(file).call
end
new(file) click to toggle source
# File lib/whatthegem/usage/extractor.rb, line 68
def initialize(file)
  @file = file
end

Public Instance Methods

call() click to toggle source
# File lib/whatthegem/usage/extractor.rb, line 72
def call
  code_blocks(file.read).map(&CodeBlock.method(:new)).reject(&:service?).select(&:ruby?)
end

Private Instance Methods

code_blocks(content) click to toggle source
# File lib/whatthegem/usage/extractor.rb, line 89
def code_blocks(content)
  __send__("#{format}_code_blocks", content)
end
format() click to toggle source
# File lib/whatthegem/usage/extractor.rb, line 80
        def format
  case file.basename.to_s
  when /\.(md|markdown)$/i
    :markdown
  else
    :rdoc
  end
end
markdown_code_blocks(content) click to toggle source
# File lib/whatthegem/usage/extractor.rb, line 93
def markdown_code_blocks(content)
  I::Kramdowns.elements(content)
    .select { |c| c.type == :codeblock }
    .map(&:value).map(&:strip)
end
rdoc_code_blocks(content) click to toggle source
# File lib/whatthegem/usage/extractor.rb, line 99
def rdoc_code_blocks(content)
  I::RDocs.parts(content).grep(RDoc::Markup::Verbatim).map(&:text)
end