class Diff::Strategy::Base

Attributes

diff[R]

Public Class Methods

new(diff = '') click to toggle source
# File lib/diff/strategy/base.rb, line 8
def initialize(diff = '')
  @diff = diff
end

Public Instance Methods

exists?() click to toggle source
# File lib/diff/strategy/base.rb, line 30
def exists?
  !to_hash.empty?
end
olds() click to toggle source
# 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) click to toggle source
# File lib/diff/strategy/base.rb, line 34
def output(format)
  case format
  when :markdown
    to_hash.map do |name, versions|
      to_markdown(name, versions[:old], versions[:updated])
    end.join("\n")
  when :text
    to_hash.map do |name, versions|
      "#{name} #{versions[:old]} => #{versions[:updated]}"
    end.join("\n")
  else
    to_hash
  end
end
to_hash() click to toggle source
# 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
to_markdown(name, old, updated) click to toggle source
# File lib/diff/strategy/base.rb, line 49
def to_markdown(name, old, updated)
  "- Updated: `#{name}` #{old} => #{updated}"
end
updates() click to toggle source
# 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