Class: TermUtils::AP::Element
- Inherits:
-
Object
- Object
- TermUtils::AP::Element
- Defined in:
- lib/term_utils/ap/element.rb
Overview
Represents a syntax element (abstract).
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#define_flag(opts = {}, &block) ⇒ TermUtils::AP::Flag
Adds a new Flag to this one.
-
#finalize!(opts = {}) ⇒ nil
Finalizes this one.
-
#flagged? ⇒ Boolean
Tests whether this one is flagged.
-
#initialize_dup(other) ⇒ Object
For dup method.
-
#multiple_occurs? ⇒ Boolean
Tests whether this one has mutiple occurs.
-
#occur_bounded? ⇒ Boolean
Tests whether the number of occurs are fixed.
Instance Attribute Details
#flags ⇒ Array<TermUtils::AP::Flag>
29 30 31 |
# File 'lib/term_utils/ap/element.rb', line 29 def flags @flags end |
#id ⇒ Symbol
23 24 25 |
# File 'lib/term_utils/ap/element.rb', line 23 def id @id end |
#max_occurs ⇒ Integer
27 28 29 |
# File 'lib/term_utils/ap/element.rb', line 27 def max_occurs @max_occurs end |
#min_occurs ⇒ 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.
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.
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.
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.
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.
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 |