Class: Xqsr3::XML::Utilities::Compare::Result

Inherits:
Object
  • Object
show all
Includes:
Quality::ParameterChecking
Defined in:
lib/xqsr3/xml/utilities/compare.rb

Overview

Class that represents the result of an XML comparison

NOTE: Sadly, we cannot create instances of FalseClass/TrueClass, to which we could then add a reason attribute, so instead we must have a results class

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status, reason, **options) ⇒ Result

Options:

:different_attributes :different_attribute_count :different_attribute_order :different_child_node_count :different_child_node_order :different_child_nodes :different_node_names :different_node_contents :parameter_is_empty :parameter_is_nil :



92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/xqsr3/xml/utilities/compare.rb', line 92

def initialize status, reason, **options

  @call_stack  =  caller(2)

  check_parameter status, 'status', types: [ ::FalseClass, ::TrueClass ]
  check_parameter reason, 'reason', type: ::Symbol, allow_nil: true

  @status    = status
  @reason    = reason

  @lhs_node  =  options[:lhs_node]
  @rhs_node  =  options[:rhs_node]
end

Instance Attribute Details

#call_stackObject (readonly)

Returns the value of attribute call_stack.



121
122
123
# File 'lib/xqsr3/xml/utilities/compare.rb', line 121

def call_stack
  @call_stack
end

#reasonObject (readonly)

Returns the value of attribute reason.



123
124
125
# File 'lib/xqsr3/xml/utilities/compare.rb', line 123

def reason
  @reason
end

#statusObject (readonly)

Returns the value of attribute status.



122
123
124
# File 'lib/xqsr3/xml/utilities/compare.rb', line 122

def status
  @status
end

Class Method Details

.different(reason, **options) ⇒ Object



116
117
118
119
# File 'lib/xqsr3/xml/utilities/compare.rb', line 116

def self.different reason, **options

  return self.new false, reason, **options
end

.return(status, reason, **options) ⇒ Object



106
107
108
109
# File 'lib/xqsr3/xml/utilities/compare.rb', line 106

def self.return status, reason, **options

  return self.new status, reason, **options
end

.same(reason = nil, **options) ⇒ Object



111
112
113
114
# File 'lib/xqsr3/xml/utilities/compare.rb', line 111

def self.same reason = nil, **options

  return self.new true, reason, **options
end

Instance Method Details

#detailsObject



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/xqsr3/xml/utilities/compare.rb', line 135

def details

  r  =  reason.to_s.gsub(/_/, ' ')

  qualifying = ''

  if @lhs_node

    qualifying  += '; ' unless qualifying.empty?
    qualifying  += "lhs-node=#{@lhs_node}"
  end

  if @rhs_node

    qualifying  += '; ' unless qualifying.empty?
    qualifying  += "rhs-node=#{@rhs_node}"
  end

  r = "#{r}: #{qualifying}" unless qualifying.empty?

  r
end

#different?Boolean

Returns:

  • (Boolean)


125
126
127
128
# File 'lib/xqsr3/xml/utilities/compare.rb', line 125

def different?

  !status
end

#same?Boolean

Returns:

  • (Boolean)


130
131
132
133
# File 'lib/xqsr3/xml/utilities/compare.rb', line 130

def same?

  status
end

#to_sObject



158
159
160
161
162
163
# File 'lib/xqsr3/xml/utilities/compare.rb', line 158

def to_s

  return 'same' if same?

  "different, because: #{details}"
end