Class: PublishingPlatformNokodiff::ChangesInFragments
- Inherits:
-
Object
- Object
- PublishingPlatformNokodiff::ChangesInFragments
- Includes:
- FormattingHelpers
- Defined in:
- lib/publishing_platform_nokodiff/changes_in_fragments.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(diff) ⇒ ChangesInFragments
constructor
A new instance of ChangesInFragments.
Methods included from FormattingHelpers
Constructor Details
#initialize(diff) ⇒ ChangesInFragments
Returns a new instance of ChangesInFragments.
4 5 6 7 8 9 10 11 |
# File 'lib/publishing_platform_nokodiff/changes_in_fragments.rb', line 4 def initialize(diff) @diff = diff @before_fragment = Nokogiri::HTML::DocumentFragment.parse("") @after_fragment = Nokogiri::HTML::DocumentFragment.parse("") @accumulated_before_text = "" @accumulated_after_text = "" end |
Instance Method Details
#call ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/publishing_platform_nokodiff/changes_in_fragments.rb', line 13 def call @diff.each do |change| case change.action when "=" no_change_emphasis(change) when "!" emphasise_change(change) when "-" emphasise_deletion(change) when "+" emphasise_addition(change) end end append_accumulated_text(before_fragment, accumulated_before_text) append_accumulated_text(after_fragment, accumulated_after_text) [before_fragment, after_fragment] end |