Class: Rosette::Core::Commands::DiffEntry
- Inherits:
-
Object
- Object
- Rosette::Core::Commands::DiffEntry
- Defined in:
- lib/rosette/core/commands/git/diff_entry.rb
Overview
Represents an added, removed, or changed phrase.
Instance Attribute Summary collapse
-
#old_phrase ⇒ Rosette::Core::Phrase
readonly
phrasebefore it was modified. -
#phrase ⇒ Rosette::Core::Phrase
readonly
The added/removed/modified phrase.
-
#state ⇒ Symbol
readonly
One of
:added,:removed, or:modified.
Instance Method Summary collapse
-
#initialize(phrase, state, old_phrase = nil) ⇒ DiffEntry
constructor
Creates a new DiffEntry.
-
#to_h ⇒ Hash
Serializes the attributes of this entry into a hash.
Constructor Details
#initialize(phrase, state, old_phrase = nil) ⇒ DiffEntry
Creates a new Rosette::Core::Commands::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_phrase ⇒ Rosette::Core::Phrase (readonly)
Returns phrase before it was modified. This value is generally only set if state is set to :modified.
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 |
#phrase ⇒ Rosette::Core::Phrase (readonly)
Returns the added/removed/modified phrase.
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 |
#state ⇒ Symbol (readonly)
Returns one of :added, :removed, or :modified.
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_h ⇒ Hash
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 |