Class: Transpec::Record
- Inherits:
-
Object
- Object
- Transpec::Record
- Includes:
- Comparable
- Defined in:
- lib/transpec/record.rb
Constant Summary collapse
- TYPES =
[:conversion, :addition, :removal, :modification]
- COMPARISON_ATTRIBUTES =
[:type_sort_key, :old_syntax, :new_syntax].freeze
Instance Attribute Summary collapse
-
#annotation ⇒ Object
readonly
Returns the value of attribute annotation.
-
#new_syntax_type ⇒ Object
readonly
Returns the value of attribute new_syntax_type.
-
#old_syntax_type ⇒ Object
readonly
Returns the value of attribute old_syntax_type.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(old_syntax, new_syntax, options = {}) ⇒ Record
constructor
A new instance of Record.
- #new_syntax ⇒ Object
- #old_syntax ⇒ Object
- #to_s ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(old_syntax, new_syntax, options = {}) ⇒ Record
Returns a new instance of Record.
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/transpec/record.rb', line 14 def initialize(old_syntax, new_syntax, = {}) # 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 = [:type] @annotation = [:annotation] fail ArgumentError, "Invalid type: #{type}" unless TYPES.include?(type) end |
Instance Attribute Details
#annotation ⇒ Object (readonly)
Returns the value of attribute annotation.
12 13 14 |
# File 'lib/transpec/record.rb', line 12 def annotation @annotation end |
#new_syntax_type ⇒ Object (readonly)
Returns the value of attribute new_syntax_type.
12 13 14 |
# File 'lib/transpec/record.rb', line 12 def new_syntax_type @new_syntax_type end |
#old_syntax_type ⇒ Object (readonly)
Returns the value of attribute old_syntax_type.
12 13 14 |
# File 'lib/transpec/record.rb', line 12 def old_syntax_type @old_syntax_type end |
Instance Method Details
#<=>(other) ⇒ Object
70 71 72 73 74 75 76 |
# 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) ⇒ Object Also known as: eql?
45 46 47 48 49 |
# 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 |
#hash ⇒ Object
53 54 55 |
# File 'lib/transpec/record.rb', line 53 def hash old_syntax_type.hash ^ new_syntax_type.hash end |
#new_syntax ⇒ Object
41 42 43 |
# File 'lib/transpec/record.rb', line 41 def new_syntax new_syntax_type && new_syntax_type.to_s end |
#old_syntax ⇒ Object
37 38 39 |
# File 'lib/transpec/record.rb', line 37 def old_syntax old_syntax_type && old_syntax_type.to_s end |
#to_s ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 |
# 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 ⇒ Object
27 28 29 30 31 32 33 34 35 |
# 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 |