Sha256: 1f1c4065b4ead1c0eabd86d9a35dfa2f4cffa875fb0abd2560bbec125cacf709

Contents?: true

Size: 1.57 KB

Versions: 46

Compression:

Stored size: 1.57 KB

Contents

# frozen_string_literal: true
module YARD
  module Parser::Ruby::Legacy
    class Statement
      attr_reader :tokens, :comments, :block
      attr_accessor :comments_range

      # @deprecated Groups are now defined by directives
      # @see Tags::GroupDirective
      attr_accessor :group

      attr_accessor :comments_hash_flag

      def initialize(tokens, block = nil, comments = nil)
        @tokens = tokens
        @block  = block
        @comments = comments
        @comments_hash_flag = false
      end

      def first_line
        to_s.split(/\n/)[0]
      end

      alias signature first_line

      def to_s(include_block = true)
        tokens.map do |token|
          RubyToken::TkBlockContents === token ? (include_block ? block.to_s : '') : token.text
        end.join
      end
      alias source to_s

      def inspect
        l = line - 1
        to_s(false).split(/\n/).map do |text|
          "\t#{l += 1}:  #{text}"
        end.join("\n")
      end

      def show
        "\t#{line}: #{first_line}"
      end

      # @return [Fixnum] the first line of Ruby source
      def line
        tokens.first.line_no
      end

      # @return [Range<Fixnum>] the first to last lines of Ruby source
      # @since 0.5.4
      def line_range
        tokens.first.line_no..tokens.last.line_no
      end

      private

      def clean_tokens(tokens)
        last_tk = nil
        tokens.reject do |tk|
          tk.is_a?(RubyToken::TkNL) ||
            (last_tk.is_a?(RubyToken::TkSPACE) &&
            last_tk.class == tk.class) && last_tk = tk
        end
      end
    end
  end
end

Version data entries

46 entries across 46 versions & 6 rubygems

Version Path
yard-0.9.33 lib/yard/parser/ruby/legacy/statement.rb
yard-0.9.32 lib/yard/parser/ruby/legacy/statement.rb
yard-0.9.31 lib/yard/parser/ruby/legacy/statement.rb
yard-0.9.30 lib/yard/parser/ruby/legacy/statement.rb
yard-0.9.29 lib/yard/parser/ruby/legacy/statement.rb
devcycle-ruby-server-sdk-2.0.0 vendor/bundle/ruby/3.0.0/gems/yard-0.9.28/lib/yard/parser/ruby/legacy/statement.rb
kinetic_sdk-5.0.20 gems/yard-0.9.25/lib/yard/parser/ruby/legacy/statement.rb
yard-0.9.28 lib/yard/parser/ruby/legacy/statement.rb
yard-0.9.27 lib/yard/parser/ruby/legacy/statement.rb
yard-0.9.26 lib/yard/parser/ruby/legacy/statement.rb
qiita_org-0.1.35 gems/ruby/2.7.0/gems/yard-0.9.25/lib/yard/parser/ruby/legacy/statement.rb
qiita_org-0.1.34 gems/ruby/2.7.0/gems/yard-0.9.25/lib/yard/parser/ruby/legacy/statement.rb
qiita_org-0.1.33 gems/ruby/2.7.0/gems/yard-0.9.25/lib/yard/parser/ruby/legacy/statement.rb
qiita_org-0.1.32 gems/ruby/2.7.0/gems/yard-0.9.25/lib/yard/parser/ruby/legacy/statement.rb
qiita_org-0.1.31 gems/ruby/2.7.0/gems/yard-0.9.25/lib/yard/parser/ruby/legacy/statement.rb
qiita_org-0.1.30 gems/ruby/2.7.0/gems/yard-0.9.25/lib/yard/parser/ruby/legacy/statement.rb
qiita_org-0.1.29 gems/ruby/2.7.0/gems/yard-0.9.25/lib/yard/parser/ruby/legacy/statement.rb
qiita_org-0.1.28 gems/ruby/2.7.0/gems/yard-0.9.25/lib/yard/parser/ruby/legacy/statement.rb
qiita_org-0.1.27 gems/ruby/2.7.0/gems/yard-0.9.25/lib/yard/parser/ruby/legacy/statement.rb
qiita_org-0.1.26 gems/ruby/2.7.0/gems/yard-0.9.25/lib/yard/parser/ruby/legacy/statement.rb