Class: Machinery::Comparison

Inherits:
Object
  • Object
show all
Defined in:
lib/comparison.rb

Overview

Copyright © 2013-2016 SUSE LLC

This program is free software; you can redistribute it and/or modify it under the terms of version 3 of the GNU General Public License as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, contact SUSE LLC.

To contact SUSE about this file by physical or electronic mail, you may find current contact information at www.suse.com

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#changedObject

Returns the value of attribute changed.



19
20
21
# File 'lib/comparison.rb', line 19

def changed
  @changed
end

#commonObject

Returns the value of attribute common.



19
20
21
# File 'lib/comparison.rb', line 19

def common
  @common
end

#name1Object

Returns the value of attribute name1.



19
20
21
# File 'lib/comparison.rb', line 19

def name1
  @name1
end

#name2Object

Returns the value of attribute name2.



19
20
21
# File 'lib/comparison.rb', line 19

def name2
  @name2
end

#only_in1Object

Returns the value of attribute only_in1.



19
20
21
# File 'lib/comparison.rb', line 19

def only_in1
  @only_in1
end

#only_in2Object

Returns the value of attribute only_in2.



19
20
21
# File 'lib/comparison.rb', line 19

def only_in2
  @only_in2
end

#scopeObject

Returns the value of attribute scope.



19
20
21
# File 'lib/comparison.rb', line 19

def scope
  @scope
end

#storeObject

Returns the value of attribute store.



19
20
21
# File 'lib/comparison.rb', line 19

def store
  @store
end

Class Method Details

.compare_scope(description1, description2, scope) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/comparison.rb', line 21

def self.compare_scope(description1, description2, scope)
  result = new
  result.store = description1.store
  result.scope = scope
  result.name1 = description1.name
  result.name2 = description2.name

  if !description1[scope]
    result.only_in2 = description2[scope]
  elsif !description2[scope]
    result.only_in1 = description1[scope]
  else
    result.only_in1, result.only_in2, result.changed, result.common =
      description1[scope].compare_with(description2[scope])
  end

  result
end

Instance Method Details

#as_description(which) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/comparison.rb', line 40

def as_description(which)
  case which
  when :one
    name = name1
    data = only_in1
  when :two
    name = name2
    data = only_in2
  when :common
    name = "common"
    data = common
  else
    raise "'which' has to be :one, :two or :common"
  end

  Machinery::SystemDescription.new(name, store, scope => data)
end

#as_jsonObject



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/comparison.rb', line 58

def as_json
  json = {}
  json["only_in1"] = only_in1.as_json if only_in1
  json["only_in2"] = only_in2.as_json if only_in2
  if changed
    json["changed"] = changed.map { |elements| [elements.first.as_json, elements.last.as_json] }
  end
  json["common"] = common.as_json if common

  json
end