Class: MARC::Spec::Queries::Tag

Inherits:
Object
  • Object
show all
Includes:
Applicable
Defined in:
lib/marc/spec/queries/tag.rb

Constant Summary collapse

LDR =

Constants

'LDR'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Applicable

#apply

Methods included from Part

#eql?, #hash, #inspect

Constructor Details

#initialize(tag, index = nil) ⇒ Tag


Initializer

Raises:

  • (ArgumentError)


23
24
25
26
27
28
# File 'lib/marc/spec/queries/tag.rb', line 23

def initialize(tag, index = nil)
  raise ArgumentError, 'Tag cannot be nil' unless tag

  @tag_exact = tag.to_s unless (@tag_re = tag_re_from(tag))
  @index = ensure_type(index, PositionOrRange, allow_nil: true)
end

Instance Attribute Details

#indexObject (readonly)


Attributes



18
19
20
# File 'lib/marc/spec/queries/tag.rb', line 18

def index
  @index
end

#tag_exactObject (readonly)


Attributes



18
19
20
# File 'lib/marc/spec/queries/tag.rb', line 18

def tag_exact
  @tag_exact
end

#tag_reObject (readonly)


Attributes



18
19
20
# File 'lib/marc/spec/queries/tag.rb', line 18

def tag_re
  @tag_re
end

Instance Method Details

#leader?Boolean


Public methods

Returns:

  • (Boolean)


33
34
35
# File 'lib/marc/spec/queries/tag.rb', line 33

def leader?
  tag_exact == LDR
end

#to_sObject


Object overrides



40
41
42
43
44
45
# File 'lib/marc/spec/queries/tag.rb', line 40

def to_s
  StringIO.new.tap do |out|
    out << tag_str
    out << "[#{index}]" if index
  end.string
end