Sha256: 6147a766d808835295bc2f8843817081eb6f573d5e26e0c46897dc6d9bfbfc0f

Contents?: true

Size: 1.5 KB

Versions: 76

Compression:

Stored size: 1.5 KB

Contents

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

      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

76 entries across 59 versions & 8 rubygems

Version Path
abaci-0.3.0 vendor/bundle/gems/yard-0.9.2/lib/yard/parser/ruby/legacy/statement.rb
abaci-0.3.0 vendor/bundle/gems/yard-0.9.1/lib/yard/parser/ruby/legacy/statement.rb
yard-0.9.5 lib/yard/parser/ruby/legacy/statement.rb
yard-0.9.4 lib/yard/parser/ruby/legacy/statement.rb
yard-0.9.3 lib/yard/parser/ruby/legacy/statement.rb
yard-0.9.2 lib/yard/parser/ruby/legacy/statement.rb
yard-0.9.1 lib/yard/parser/ruby/legacy/statement.rb
yard-0.9.0 lib/yard/parser/ruby/legacy/statement.rb
yard-0.8.7.6 lib/yard/parser/ruby/legacy/statement.rb
yard-0.8.7.5 lib/yard/parser/ruby/legacy/statement.rb
climine-0.0.7 vendor/bundle/ruby/2.1.0/gems/yard-0.8.7.3/lib/yard/parser/ruby/legacy/statement.rb
climine-0.0.7 vendor/bundle/ruby/2.0.0/gems/yard-0.8.7.3/lib/yard/parser/ruby/legacy/statement.rb
climine-0.0.6 vendor/bundle/ruby/2.0.0/gems/yard-0.8.7.3/lib/yard/parser/ruby/legacy/statement.rb
climine-0.0.5 vendor/bundle/ruby/2.0.0/gems/yard-0.8.7.3/lib/yard/parser/ruby/legacy/statement.rb
yard-0.8.7.4 lib/yard/parser/ruby/legacy/statement.rb
climine-0.0.4 vendor/bundle/ruby/2.0.0/gems/yard-0.8.7.3/lib/yard/parser/ruby/legacy/statement.rb
climine-0.0.3 vendor/bundle/ruby/2.0.0/gems/yard-0.8.7.3/lib/yard/parser/ruby/legacy/statement.rb
mango-0.8.0 vendor/bundler/ruby/2.1.0/gems/yard-0.8.7.3/lib/yard/parser/ruby/legacy/statement.rb
mango-0.7.1 vendor/bundler/ruby/2.0.0/gems/yard-0.8.7.3/lib/yard/parser/ruby/legacy/statement.rb
mango-0.7.0 vendor/bundler/ruby/2.0.0/gems/yard-0.8.7.3/lib/yard/parser/ruby/legacy/statement.rb