class Transpec::Record

Constants

COMPARISON_ATTRIBUTES
TYPES

Attributes

annotation[R]
new_syntax_type[R]
old_syntax_type[R]

Public Class Methods

new(old_syntax, new_syntax, options = {}) click to toggle source
# File lib/transpec/record.rb, line 14
def initialize(old_syntax, new_syntax, options = {})
  # Keep these syntax data as symbols for:
  #   * Better memory footprint
  #   * Better summarizing performance in Report
  @old_syntax_type = old_syntax && old_syntax.to_sym
  @new_syntax_type = new_syntax && new_syntax.to_sym

  @type = options[:type]
  @annotation = options[:annotation]

  fail ArgumentError, "Invalid type: #{type}" unless TYPES.include?(type)
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/transpec/record.rb, line 70
def <=>(other)
  COMPARISON_ATTRIBUTES.each do |attribute|
    result = send(attribute) <=> other.send(attribute)
    return result unless result.zero?
  end
  0
end
==(other) click to toggle source
# File lib/transpec/record.rb, line 45
def ==(other)
  self.class == other.class &&
    old_syntax_type == other.old_syntax_type &&
    new_syntax_type == other.new_syntax_type
end
Also aliased as: eql?
eql?(other)
Alias for: ==
hash() click to toggle source
# File lib/transpec/record.rb, line 53
def hash
  old_syntax_type.hash ^ new_syntax_type.hash
end
new_syntax() click to toggle source
# File lib/transpec/record.rb, line 41
def new_syntax
  new_syntax_type && new_syntax_type.to_s
end
old_syntax() click to toggle source
# File lib/transpec/record.rb, line 37
def old_syntax
  old_syntax_type && old_syntax_type.to_s
end
to_s() click to toggle source
# File lib/transpec/record.rb, line 57
def to_s
  string = type.to_s.capitalize

  string << case type
            when :conversion, :modification
              " from `#{old_syntax_type}` to `#{new_syntax_type}`"
            when :addition
              " of `#{new_syntax_type}`"
            when :removal
              " of `#{old_syntax_type}`"
            end
end
type() click to toggle source
# File lib/transpec/record.rb, line 27
def type
  @type ||= if old_syntax_type && new_syntax_type
              :conversion
            elsif new_syntax_type
              :addition
            else
              :removal
            end
end

Private Instance Methods

type_sort_key() click to toggle source
# File lib/transpec/record.rb, line 80
def type_sort_key
  case type
  when :conversion   then 1
  when :modification then 2
  when :addition     then 3
  when :removal      then 4
  end
end