Class: WhatTheGem::Usage::Extractor::CodeBlock
- Defined in:
- lib/whatthegem/usage/extractor.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
Instance Method Summary collapse
-
#initialize(body) ⇒ CodeBlock
constructor
A new instance of CodeBlock.
- #ruby? ⇒ Boolean
- #service? ⇒ Boolean
- #to_h ⇒ Object
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
#body ⇒ Object
Returns the value of attribute body
30 31 32 |
# File 'lib/whatthegem/usage/extractor.rb', line 30 def body @body end |
Instance Method Details
#ruby? ⇒ 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
45 46 47 |
# File 'lib/whatthegem/usage/extractor.rb', line 45 def service? body.match?(REMOVE_BLOCKS_RE) end |
#to_h ⇒ Object
49 50 51 |
# File 'lib/whatthegem/usage/extractor.rb', line 49 def to_h {body: body} end |