Class: Diff::Strategy::Base
- Inherits:
-
Object
- Object
- Diff::Strategy::Base
- Defined in:
- lib/diff/strategy/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#diff ⇒ Object
readonly
Returns the value of attribute diff.
Instance Method Summary collapse
- #exists? ⇒ Boolean
-
#initialize(diff = '') ⇒ Base
constructor
A new instance of Base.
- #olds ⇒ Object
- #output(format) ⇒ Object
- #to_hash ⇒ Object
- #updates ⇒ Object
Constructor Details
#initialize(diff = '') ⇒ Base
Returns a new instance of Base.
8 9 10 |
# File 'lib/diff/strategy/base.rb', line 8 def initialize(diff = '') @diff = diff end |
Instance Attribute Details
#diff ⇒ Object (readonly)
Returns the value of attribute diff.
6 7 8 |
# File 'lib/diff/strategy/base.rb', line 6 def diff @diff end |
Instance Method Details
#exists? ⇒ Boolean
30 31 32 |
# File 'lib/diff/strategy/base.rb', line 30 def exists? !to_hash.empty? end |
#olds ⇒ Object
12 13 14 15 16 |
# File 'lib/diff/strategy/base.rb', line 12 def olds # return hash object # {"library-name" => "old_version", ...} raise NotImplementedError, "You must implement #{self.class}##{__method__}" end |
#output(format) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/diff/strategy/base.rb', line 34 def output(format) case format when :text to_hash.map do |name, versions| "#{name} #{versions[:old]} => #{versions[:updated]}" end.join("\n") when :markdown to_hash.map do |name, versions| "- `#{name}` #{versions[:old]} => #{versions[:updated]}" end.join("\n") else to_hash end end |
#to_hash ⇒ Object
24 25 26 27 28 |
# File 'lib/diff/strategy/base.rb', line 24 def to_hash updates.each_with_object({}) do |(name, version), hash| hash[name] = { old: olds[name], updated: version } end end |
#updates ⇒ Object
18 19 20 21 22 |
# File 'lib/diff/strategy/base.rb', line 18 def updates # return hash object # {"library-name" => "updated_version", ...} raise NotImplementedError, "You must implement #{self.class}##{__method__}" end |