Class: TermUtils::AP::Element

Inherits:
Object
  • Object
show all
Defined in:
lib/term_utils/ap/element.rb

Overview

Represents a syntax element (abstract).

Direct Known Subclasses

Level, Parameter

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#flagsArray<TermUtils::AP::Flag>

Returns:



29
30
31
# File 'lib/term_utils/ap/element.rb', line 29

def flags
  @flags
end

#idSymbol

Returns:

  • (Symbol)


23
24
25
# File 'lib/term_utils/ap/element.rb', line 23

def id
  @id
end

#max_occursInteger

Returns:

  • (Integer)


27
28
29
# File 'lib/term_utils/ap/element.rb', line 27

def max_occurs
  @max_occurs
end

#min_occursInteger

Returns:

  • (Integer)


25
26
27
# File 'lib/term_utils/ap/element.rb', line 25

def min_occurs
  @min_occurs
end

Instance Method Details

#define_flag(opts = {}, &block) ⇒ TermUtils::AP::Flag

Adds a new Flag to this one.

Parameters:

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :label (String)
  • :flavor (Symbol)

    ‘:anchor`, `:long`, `:short`.

Returns:



70
71
72
73
74
75
# File 'lib/term_utils/ap/element.rb', line 70

def define_flag(opts = {}, &block)
  new_flag = TermUtils::AP::Flag.new(opts)
  @flags << new_flag
  block.call(new_flag) if block
  new_flag
end

#finalize!(opts = {}) ⇒ nil

Finalizes this one. Internal use.

Returns:

  • (nil)

Raises:



42
43
44
45
46
47
48
49
# File 'lib/term_utils/ap/element.rb', line 42

def finalize!(opts = {})
  raise TermUtils::AP::SyntaxError, "min_occurs must be equal or greater than 0" unless (@min_occurs.is_a? Integer) && (@min_occurs >= 0)
  raise TermUtils::AP::SyntaxError, "max_occurs must be equal or greater than min_occurs" unless !occur_bounded? || (@max_occurs >= @min_occurs)
  unless @id
    opts[:anonymous] += 1
    @id = "anonymous#{opts[:anonymous]}".intern
  end
end

#flagged?Boolean

Tests whether this one is flagged.

Returns:

  • (Boolean)


62
63
64
# File 'lib/term_utils/ap/element.rb', line 62

def flagged?
  !@flags.empty?
end

#initialize_dup(other) ⇒ Object

For dup method.



31
32
33
34
35
36
37
38
39
# File 'lib/term_utils/ap/element.rb', line 31

def initialize_dup(other)
  if other.flags
    @flags = []
    other.flags.each do |f|
      @flags << f.dup
    end
  end
  super
end

#multiple_occurs?Boolean

Tests whether this one has mutiple occurs.

Returns:

  • (Boolean)


52
53
54
# File 'lib/term_utils/ap/element.rb', line 52

def multiple_occurs?
  (@max_occurs == nil) || (@max_occurs == :infinity) || ((@max_occurs.is_a? Integer) && (@max_occurs > 1))
end

#occur_bounded?Boolean

Tests whether the number of occurs are fixed.

Returns:

  • (Boolean)


57
58
59
# File 'lib/term_utils/ap/element.rb', line 57

def occur_bounded?
  (@max_occurs != nil) && (@max_occurs != :infinity) && (@max_occurs.is_a? Integer)
end