Module: Yadtfp::Outputters::Diffable
- Included in:
- Pretty
- Defined in:
- lib/yadtfp/outputters/diffable.rb
Overview
Module exists to extract out the common methods in outputters.
Include this module Diffable
in each outputters defined.
Instance Attribute Summary collapse
-
#diff ⇒ Object
readonly
Returns the value of attribute diff.
Instance Method Summary collapse
-
#appends ⇒ Object
Returns an array containing all the appends.
-
#by_type(type) ⇒ Object
private
Filters and returns the subset of difference by type.
-
#changes ⇒ Object
Returns an array containing all the changes.
-
#deletes ⇒ Object
Returns an array containing all the deletes.
-
#initialize(arr = []) ⇒ Object
Saves supplied difference array.
Instance Attribute Details
#diff ⇒ Object (readonly)
Returns the value of attribute diff.
11 12 13 |
# File 'lib/yadtfp/outputters/diffable.rb', line 11 def diff @diff end |
Instance Method Details
#appends ⇒ Object
Returns an array containing all the appends.
40 41 42 |
# File 'lib/yadtfp/outputters/diffable.rb', line 40 def appends by_type('a') end |
#by_type(type) ⇒ Object (private)
Filters and returns the subset of difference by type
type
can be one of:
c
- Change
a
- Append
d
- Delete
68 69 70 |
# File 'lib/yadtfp/outputters/diffable.rb', line 68 def by_type(type) @diff.select { |d| d[:type] == type } end |
#changes ⇒ Object
Returns an array containing all the changes.
31 32 33 |
# File 'lib/yadtfp/outputters/diffable.rb', line 31 def changes by_type('c') end |
#deletes ⇒ Object
Returns an array containing all the deletes.
49 50 51 |
# File 'lib/yadtfp/outputters/diffable.rb', line 49 def deletes by_type('d') end |
#initialize(arr = []) ⇒ Object
Saves supplied difference array.
Parameter arr
must be an array of difference hashes.
Raises ArgumentError
if supplied arr
is not an Array
type.
20 21 22 23 24 |
# File 'lib/yadtfp/outputters/diffable.rb', line 20 def initialize(arr = []) throw ArgumentError, "`arr` must be an array" if !arr.is_a?(::Array) @diff = arr end |