lib/rasn1/model.rb in rasn1-0.4.0 vs lib/rasn1/model.rb in rasn1-0.5.0

- old
+ new

@@ -258,14 +258,22 @@ else super end end + # @return [String] def inspect(level=0) - ' ' * level + "#{type} #{root.inspect(-level)}" + ' ' * level + "#{@root} (#{type}) #{root.inspect(-level)}" end + # Objects are equal if they have same class AND same DER + # @param [Base] other + # @return [Boolean] + def==(other) + (other.class == self.class) && (other.to_der == self.to_der) + end + private def is_composed?(el) [Types::Sequence, Types::Set].include? el.class end @@ -319,21 +327,21 @@ end end end def private_to_h(element) - if element.value.is_a? Array + if element.is_a?(Types::SequenceOf) or + (element.is_a?(Model) and element.root.is_a?(Types::SequenceOf)) + element.value.map { |el| private_to_h(el) } + elsif element.value.is_a? Array h = {} element.value.each do |subel| case subel when Types::Sequence, Types::Set h[subel.name] = private_to_h(subel) when Model - h[@elements.key(subel)] = subel.to_h[subel.name] - when Hash, Array - # Array of Hash for SequenceOf and SetOf - # Array of Array of... of Hash are nested SequenceOf or SetOf - return element.value + this_name = @elements.key(subel) || element.name + h[this_name] = subel.to_h[subel.name] else next if subel.value.nil? and subel.optional? h[subel.name] = subel.value end end