Class: Docks::Parsers::CoffeeScript

Inherits:
Base
  • Object
show all
Defined in:
lib/docks/parsers/coffeescript_parser.rb

Instance Attribute Summary

Attributes inherited from Base

#comment_line_pattern, #comment_pattern, #pattern_block_extractor, #symbol_block_extractor

Instance Method Summary collapse

Methods inherited from Base

#parse, #parse_comment_block

Constructor Details

#initializeCoffeeScript

Returns a new instance of CoffeeScript.



6
7
8
9
10
# File 'lib/docks/parsers/coffeescript_parser.rb', line 6

def initialize
  @comment_pattern = /#/
  @first_non_code_line_pattern = /[\w\$]/
  setup_regexes
end

Instance Method Details

#symbol_details_from_first_line(first_code_line) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/docks/parsers/coffeescript_parser.rb', line 12

def symbol_details_from_first_line(first_code_line)
  first_code_line.strip!

  type = case first_code_line
    when /^class/ then Docks::Types::Symbol::CLASS
    when /^.*?[\-\=]\>/ then Docks::Types::Symbol::FUNCTION
    else Docks::Types::Symbol::VARIABLE
  end

  clean_first_line = first_code_line.split(/[=:,]/).first.gsub(/class\s+/, "").split(".").last.strip
  bracket_check = clean_first_line.split(/['"]/)

  name = bracket_check.length > 1 ? bracket_check[-2] : clean_first_line

  { name: name, symbol_type: type }
end