Class: Mab2::Document

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

Defined Under Namespace

Classes: Scope

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml, options = {}) ⇒ Document

Returns a new instance of Document.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/mab2/document.rb', line 10

def initialize(xml, options = {})
  @badgerfish_hash = Badgerfish::Parser.new.load(xml, options)

  # the original mabmapper dsl is buggy at certain points, but this
  # behaviour might be needed for certain legacy rules
  @legacy_mabmapper_mode =
  if options[:legacy_mabmapper_mode].nil?
    false
  else
    !!options[:legacy_mabmapper_mode]
  end

  create_controlfields_tag_index
  create_datafields_tag_index
end

Instance Attribute Details

#legacy_mabmapper_modeObject

Returns the value of attribute legacy_mabmapper_mode.



8
9
10
# File 'lib/mab2/document.rb', line 8

def legacy_mabmapper_mode
  @legacy_mabmapper_mode
end

Instance Method Details

#controlfield(tag) ⇒ Object

dsl methods



29
30
31
32
33
34
35
36
37
# File 'lib/mab2/document.rb', line 29

def controlfield(tag)
  controlfields_by_tag(tag)
  .first
  .try do |controlfield|
    controlfield["$"].chars.map! do |char|
      char == "|" ? nil : char
    end
  end || []
end

#controlfields_by_tag(tag) ⇒ Object

other public methods



50
51
52
53
54
# File 'lib/mab2/document.rb', line 50

def controlfields_by_tag(tag)
  (@controlfields_tag_index[tag] || []).map do |index|
    controlfields[index]
  end
end

#datafields_by_tag(tag) ⇒ Object



56
57
58
59
60
# File 'lib/mab2/document.rb', line 56

def datafields_by_tag(tag)
  (@datafields_tag_index[tag] || []).map do |index|
    datafields[index]
  end
end

#docObject



39
40
41
# File 'lib/mab2/document.rb', line 39

def doc
  self
end

#field(tag, options = {}) ⇒ Object



43
44
45
# File 'lib/mab2/document.rb', line 43

def field(tag, options = {})
  Scope.new(options.merge(document: self, tag: tag))
end

#legacy_mabmapper_mode?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/mab2/document.rb', line 62

def legacy_mabmapper_mode?
  @legacy_mabmapper_mode
end