Module: CommentExtractor::Extractor::Concerns::SimpleExtractor::ClassMethods

Includes:
CodeObject::Comment::Type
Defined in:
lib/comment_extractor/extractor/concerns/simple_extractor.rb

Constant Summary

Constants included from CodeObject::Comment::Type

CodeObject::Comment::Type::BLOCK_COMMENT, CodeObject::Comment::Type::ONE_LINER_COMMENT

Instance Method Summary collapse

Instance Method Details

#append_bracket(start_with, end_with) ⇒ Object



72
73
74
75
# File 'lib/comment_extractor/extractor/concerns/simple_extractor.rb', line 72

def append_bracket(start_with, end_with)
  @brackets ||= []
  @brackets << { start_with: start_with, end_with: end_with }
end

#comment(start_with: nil, end_with: nil, type: ONE_LINER_COMMENT) ⇒ Object

Raises:

  • (ArgumentError)


33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/comment_extractor/extractor/concerns/simple_extractor.rb', line 33

def comment(start_with: nil, end_with: nil, type: ONE_LINER_COMMENT)
  @comment_regexp ||= []
  # Check required attributes
  raise ArgumentError unless [type, start_with].all?

  definition = { start_with: build_regexp(start_with), type: type, end_with: end_with }

  if type == BLOCK_COMMENT
    definition[:end_with] = build_regexp(end_with, Regexp::MULTILINE)
  end

  @comment_regexp << definition
end

#define_bracket(bracket, options = 0) ⇒ Object



52
53
54
55
56
57
58
59
60
61
# File 'lib/comment_extractor/extractor/concerns/simple_extractor.rb', line 52

def define_bracket(bracket, options = 0)
  start_regexp = build_regexp(bracket)
  end_regexp = if bracket.is_a?(Regexp)
                  join_regexp(/(?<!\\)/, bracket)
                else
                  /(?<!\\)#{bracket}/
                end
  end_regexp = Regexp.new(end_regexp.source, options)
  append_bracket(start_regexp, end_regexp)
end

#define_complicate_condition(&proc_object) ⇒ Object



77
78
79
80
# File 'lib/comment_extractor/extractor/concerns/simple_extractor.rb', line 77

def define_complicate_condition(&proc_object)
  @complicate_conditions ||= []
  @complicate_conditions << proc_object
end

#define_default_bracketObject



67
68
69
70
# File 'lib/comment_extractor/extractor/concerns/simple_extractor.rb', line 67

def define_default_bracket
  define_bracket('"', Regexp::MULTILINE)
  define_bracket("'", Regexp::MULTILINE)
end

#define_ignore_patterns(*patterns) ⇒ Object



47
48
49
50
# File 'lib/comment_extractor/extractor/concerns/simple_extractor.rb', line 47

def define_ignore_patterns(*patterns)
  @ignore_patterns ||= []
  @ignore_patterns += patterns
end

#define_regexp_bracketObject



63
64
65
# File 'lib/comment_extractor/extractor/concerns/simple_extractor.rb', line 63

def define_regexp_bracket
  append_bracket(%r!/(?=[^/])!, /(?<!\\)\//)
end

#included(k) ⇒ Object



27
28
29
30
31
# File 'lib/comment_extractor/extractor/concerns/simple_extractor.rb', line 27

def included(k)
  self.instance_variables.each do |key|
    k.instance_variable_set(key, self.instance_variable_get(key))
  end
end