Sha256: b650de0ed16b41006a42b0fd7ffcd9227d0f0821e9ffec59a013475e390f0864

Contents?: true

Size: 849 Bytes

Versions: 3

Compression:

Stored size: 849 Bytes

Contents

require_relative "base_parser.rb"

module Docks
  module Parsers
    class CoffeeScript < Base
      def initialize
        @comment_pattern = /#/
        @first_non_code_line_pattern = /[\w\$]/
        setup_regexes
      end

      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
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
docks_app-0.0.3 lib/docks/parsers/coffeescript_parser.rb
docks_app-0.0.2 lib/docks/parsers/coffeescript_parser.rb
docks_app-0.0.1 lib/docks/parsers/coffeescript_parser.rb