Class: Diff::Strategy::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/diff/strategy/base.rb

Direct Known Subclasses

Bundler

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#diffObject (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

Returns:

  • (Boolean)


30
31
32
# File 'lib/diff/strategy/base.rb', line 30

def exists?
  !to_hash.empty?
end

#oldsObject

Raises:

  • (NotImplementedError)


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_hashObject



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

#updatesObject

Raises:

  • (NotImplementedError)


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