Class: Rosette::Core::Commands::DiffEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/rosette/core/commands/git/diff_entry.rb

Overview

Represents an added, removed, or changed phrase.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(phrase, state, old_phrase = nil) ⇒ DiffEntry


25
26
27
28
29
# File 'lib/rosette/core/commands/git/diff_entry.rb', line 25

def initialize(phrase, state, old_phrase = nil)
  @phrase = phrase
  @state = state
  @old_phrase = old_phrase
end

Instance Attribute Details

#old_phraseRosette::Core::Phrase (readonly)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rosette/core/commands/git/diff_entry.rb', line 16

class DiffEntry
  attr_reader :phrase, :state, :old_phrase

  # Creates a new {DiffEntry}.
  #
  # @param [Rosette::Core::Phrase] phrase The added/removed/modified phrase.
  # @param [Symbol] state One of +:added+, +:removed+, or +:modified+.
  # @param [Rosette::Core::Phrase] old_phrase +phrase+ before it was modified.
  #   This argument is usually only included if +state+ is +:modified+.
  def initialize(phrase, state, old_phrase = nil)
    @phrase = phrase
    @state = state
    @old_phrase = old_phrase
  end

  # Serializes the attributes of this entry into a hash.
  #
  # @return [Hash] the attributes of the phrase. If +state+ is set to +:modified+,
  #   the key of the old phrase is included as +:old_key+.
  def to_h
    phrase.to_h.tap do |hash|
      hash[:old_key] = old_phrase.key if old_phrase
    end
  end
end

#phraseRosette::Core::Phrase (readonly)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rosette/core/commands/git/diff_entry.rb', line 16

class DiffEntry
  attr_reader :phrase, :state, :old_phrase

  # Creates a new {DiffEntry}.
  #
  # @param [Rosette::Core::Phrase] phrase The added/removed/modified phrase.
  # @param [Symbol] state One of +:added+, +:removed+, or +:modified+.
  # @param [Rosette::Core::Phrase] old_phrase +phrase+ before it was modified.
  #   This argument is usually only included if +state+ is +:modified+.
  def initialize(phrase, state, old_phrase = nil)
    @phrase = phrase
    @state = state
    @old_phrase = old_phrase
  end

  # Serializes the attributes of this entry into a hash.
  #
  # @return [Hash] the attributes of the phrase. If +state+ is set to +:modified+,
  #   the key of the old phrase is included as +:old_key+.
  def to_h
    phrase.to_h.tap do |hash|
      hash[:old_key] = old_phrase.key if old_phrase
    end
  end
end

#stateSymbol (readonly)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rosette/core/commands/git/diff_entry.rb', line 16

class DiffEntry
  attr_reader :phrase, :state, :old_phrase

  # Creates a new {DiffEntry}.
  #
  # @param [Rosette::Core::Phrase] phrase The added/removed/modified phrase.
  # @param [Symbol] state One of +:added+, +:removed+, or +:modified+.
  # @param [Rosette::Core::Phrase] old_phrase +phrase+ before it was modified.
  #   This argument is usually only included if +state+ is +:modified+.
  def initialize(phrase, state, old_phrase = nil)
    @phrase = phrase
    @state = state
    @old_phrase = old_phrase
  end

  # Serializes the attributes of this entry into a hash.
  #
  # @return [Hash] the attributes of the phrase. If +state+ is set to +:modified+,
  #   the key of the old phrase is included as +:old_key+.
  def to_h
    phrase.to_h.tap do |hash|
      hash[:old_key] = old_phrase.key if old_phrase
    end
  end
end

Instance Method Details

#to_hHash

Serializes the attributes of this entry into a hash.


35
36
37
38
39
# File 'lib/rosette/core/commands/git/diff_entry.rb', line 35

def to_h
  phrase.to_h.tap do |hash|
    hash[:old_key] = old_phrase.key if old_phrase
  end
end