Class: WhatTheGem::Usage::Extractor::CodeBlock

Inherits:
Struct
  • Object
show all
Defined in:
lib/whatthegem/usage/extractor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body) ⇒ CodeBlock

Returns a new instance of CodeBlock.



31
32
33
# File 'lib/whatthegem/usage/extractor.rb', line 31

def initialize(body)
  super(try_sanitize(body))
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body

Returns:

  • (Object)

    the current value of body



30
31
32
# File 'lib/whatthegem/usage/extractor.rb', line 30

def body
  @body
end

Instance Method Details

#ruby?Boolean

Returns:

  • (Boolean)


35
36
37
38
39
40
41
42
43
# 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?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/whatthegem/usage/extractor.rb', line 45

def service?
  body.match?(REMOVE_BLOCKS_RE)
end

#to_hObject



49
50
51
# File 'lib/whatthegem/usage/extractor.rb', line 49

def to_h
  {body: body}
end