Sha256: e7b3cce7b62bd417f6e1c2296726986481513cfb734c254cefadf00cd0832f1f

Contents?: true

Size: 1.06 KB

Versions: 32

Compression:

Stored size: 1.06 KB

Contents

module CC
  module Analyzer
    class LocationDescription
      def initialize(location, suffix = "")
        @location = location
        @suffix = suffix
      end

      def to_s
        str = ""
        if location["lines"]
          str << render_lines
        elsif positions = location["positions"]
          str << render_position(positions["begin"])

          if positions["end"]
            str << "-"
            str << render_position(positions["end"])
          end
        end

        str << suffix unless str.blank?

        str
      end

      private

      attr_reader :location, :suffix

      def render_lines
        str = location["lines"]["begin"].to_s
        str << "-#{location["lines"]["end"]}" if location["lines"]["end"]
        str
      end

      def render_position(position)
        str = ""

        if position["line"]
          str << position["line"].to_s
          str << ":#{position["column"]}" if position["column"]
        elsif position["offset"]
          str << position["offset"].to_s
        end

        str
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
codeclimate-0.2.12 lib/cc/analyzer/location_description.rb
codeclimate-0.2.11 lib/cc/analyzer/location_description.rb
codeclimate-0.2.9 lib/cc/analyzer/location_description.rb
codeclimate-0.2.7 lib/cc/analyzer/location_description.rb
codeclimate-0.2.6 lib/cc/analyzer/location_description.rb
codeclimate-0.2.4 lib/cc/analyzer/location_description.rb
codeclimate-0.2.2 lib/cc/analyzer/location_description.rb
codeclimate-0.2.1 lib/cc/analyzer/location_description.rb
codeclimate-0.2 lib/cc/analyzer/location_description.rb
codeclimate-0.1.5 lib/cc/analyzer/location_description.rb
codeclimate-0.1.4 lib/cc/analyzer/location_description.rb
codeclimate-0.1.3 lib/cc/analyzer/location_description.rb
codeclimate-0.1.2 lib/cc/analyzer/location_description.rb
codeclimate-0.1.0 lib/cc/analyzer/location_description.rb
codeclimate-0.0.25 lib/cc/analyzer/location_description.rb
codeclimate-0.0.24 lib/cc/analyzer/location_description.rb
codeclimate-0.0.23 lib/cc/analyzer/location_description.rb
codeclimate-0.0.22 lib/cc/analyzer/location_description.rb
codeclimate-0.0.21 lib/cc/analyzer/location_description.rb
codeclimate-0.0.18 lib/cc/analyzer/location_description.rb