Class: WhatTheGem::Usage::Extractor

Inherits:
Object
  • Object
show all
Extended by:
I::Callable
Defined in:
lib/whatthegem/usage/extractor.rb

Overview

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`

Defined Under Namespace

Classes: CodeBlock

Constant Summary collapse

REMOVE_BLOCKS =
[
  %{gem ['"]},      # gem install instructions
  'gem install',
  'bundle install',
  'rake ',

  'rails g ',       # rails generator
  'git clone',      # instructions to contribute

  '\\$',            # bash command
  'ruby (\S+)$',    # run one Ruby command

  'Copyright '      # Sometimes they render license in ```
]
REMOVE_BLOCKS_RE =
/^#{REMOVE_BLOCKS.join('|')}/

Class Method Summary collapse

Instance Method Summary collapse

Methods included from I::Callable

to_proc

Constructor Details

#initialize(file) ⇒ Extractor

Returns a new instance of Extractor.



68
69
70
# File 'lib/whatthegem/usage/extractor.rb', line 68

def initialize(file)
  @file = file
end

Class Method Details

.call(file) ⇒ Object



64
65
66
# File 'lib/whatthegem/usage/extractor.rb', line 64

def self.call(file)
  new(file).call
end

Instance Method Details

#callObject



72
73
74
# File 'lib/whatthegem/usage/extractor.rb', line 72

def call
  code_blocks(file.read).map(&CodeBlock.method(:new)).reject(&:service?).select(&:ruby?)
end