Class: Mab2::Document
- Inherits:
-
Object
- Object
- Mab2::Document
- Defined in:
- lib/mab2/document.rb
Defined Under Namespace
Classes: Scope
Instance Attribute Summary collapse
-
#legacy_mabmapper_mode ⇒ Object
Returns the value of attribute legacy_mabmapper_mode.
Instance Method Summary collapse
-
#controlfield(tag) ⇒ Object
dsl methods.
-
#controlfields_by_tag(tag) ⇒ Object
other public methods.
- #datafields_by_tag(tag) ⇒ Object
- #doc ⇒ Object
- #field(tag, options = {}) ⇒ Object
-
#initialize(xml, options = {}) ⇒ Document
constructor
A new instance of Document.
- #legacy_mabmapper_mode? ⇒ Boolean
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, = {}) @badgerfish_hash = Badgerfish::Parser.new.load(xml, ) # the original mabmapper dsl is buggy at certain points, but this # behaviour might be needed for certain legacy rules @legacy_mabmapper_mode = if [:legacy_mabmapper_mode].nil? false else !![:legacy_mabmapper_mode] end create_controlfields_tag_index create_datafields_tag_index end |
Instance Attribute Details
#legacy_mabmapper_mode ⇒ Object
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 |
#doc ⇒ Object
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, = {}) Scope.new(.merge(document: self, tag: tag)) end |
#legacy_mabmapper_mode? ⇒ Boolean
62 63 64 |
# File 'lib/mab2/document.rb', line 62 def legacy_mabmapper_mode? @legacy_mabmapper_mode end |