Sha256: a8108ab1d1ec62004fd1b21c47160496a06782c9fb02266a3981766e102f4a46

Contents?: true

Size: 1.43 KB

Versions: 20

Compression:

Stored size: 1.43 KB

Contents

module Ddr::Models::Structures
  #
  # Wraps a Nokogiri (XML) 'div' node
  #
  class Div < SimpleDelegator

    def id
      self['ID']
    end

    def label
      self['LABEL']
    end

    def order
      self['ORDER']
    end

    def orderlabel
      self['ORDERLABEL']
    end

    def type
      self['TYPE']
    end

    def divs
      xpath('xmlns:div').map { |node| Div.new(node) }
    end

    def fptrs
      xpath('xmlns:fptr').map { |node| Fptr.new(node) }
    end

    def mptrs
      xpath('xmlns:mptr').map { |node| Mptr.new(node) }
    end

    def <=>(other)
      order.to_i <=> other.order.to_i
    end

    def dereferenced_hash
      contents = []
      contents.concat(divs.map { |div| div.dereferenced_hash }) unless divs.empty?
      contents.concat(fptrs.map { |fptr| fptr.dereferenced_hash }) unless fptrs.empty?
      contents.concat(mptrs.map { |mptr| mptr.dereferenced_hash }) unless mptrs.empty?
      dh = { id: id, label: label, order: order, orderlabel: orderlabel, type: type }.compact
      dh[:contents] = contents unless contents.empty?
      dh
    end

    def self.build(args)
      node = Nokogiri::XML::Node.new('div', args[:document])
      node['ID'] = args[:id] if args[:id]
      node['LABEL'] = args[:label] if args[:label]
      node['ORDER'] = args[:order] if args[:order]
      node['ORDERLABEL'] = args[:orderlabel] if args[:orderlabel]
      node['TYPE'] = args[:type] if args[:type]
      node
    end

  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
ddr-models-2.11.0 lib/ddr/models/structures/div.rb
ddr-models-2.10.2 lib/ddr/models/structures/div.rb
ddr-models-2.10.1 lib/ddr/models/structures/div.rb
ddr-models-2.10.0 lib/ddr/models/structures/div.rb
ddr-models-2.10.0.rc2 lib/ddr/models/structures/div.rb
ddr-models-2.10.0.rc1 lib/ddr/models/structures/div.rb
ddr-models-2.9.2 lib/ddr/models/structures/div.rb
ddr-models-2.9.1 lib/ddr/models/structures/div.rb
ddr-models-2.9.0 lib/ddr/models/structures/div.rb
ddr-models-2.9.0.rc1 lib/ddr/models/structures/div.rb
ddr-models-2.8.0 lib/ddr/models/structures/div.rb
ddr-models-2.8.0.rc1 lib/ddr/models/structures/div.rb
ddr-models-2.7.6 lib/ddr/models/structures/div.rb
ddr-models-2.7.5 lib/ddr/models/structures/div.rb
ddr-models-2.7.4 lib/ddr/models/structures/div.rb
ddr-models-2.7.3 lib/ddr/models/structures/div.rb
ddr-models-2.7.2 lib/ddr/models/structures/div.rb
ddr-models-2.7.1 lib/ddr/models/structures/div.rb
ddr-models-2.7.0 lib/ddr/models/structures/div.rb
ddr-models-2.7.0.rc1 lib/ddr/models/structures/div.rb