Class: TermUtils::AP::Article
- Inherits:
-
Object
- Object
- TermUtils::AP::Article
- Defined in:
- lib/term_utils/ap/article.rb
Overview
Represents a Article.
Instance Attribute Summary collapse
-
#format ⇒ String
‘%d`, `%s`.
- #id ⇒ Symbol
- #max_occurs ⇒ Integer
- #min_occurs ⇒ Integer
-
#type ⇒ Symbol
‘:integer`, `:string`.
Instance Method Summary collapse
-
#finalize!(opts = {}) ⇒ nil
Finalizes this one.
-
#initialize(opts = {}) ⇒ Article
constructor
Constructs a new Article.
-
#multiple_occurs? ⇒ Boolean
Tests whether this one has mutiple occurs.
-
#occur_bounded? ⇒ Boolean
Tests whether the number of occurs is fixed.
Constructor Details
#initialize(opts = {}) ⇒ Article
Constructs a new Article.
41 42 43 44 45 46 47 |
# File 'lib/term_utils/ap/article.rb', line 41 def initialize(opts = {}) @id = opts.fetch(:id, nil) @min_occurs = opts.fetch(:min_occurs, 1) @max_occurs = opts.fetch(:max_occurs, 1) @type = opts.fetch(:type, :string) @format = opts.fetch(:format, '%s') end |
Instance Attribute Details
#format ⇒ String
Returns ‘%d`, `%s`.
32 33 34 |
# File 'lib/term_utils/ap/article.rb', line 32 def format @format end |
#id ⇒ Symbol
24 25 26 |
# File 'lib/term_utils/ap/article.rb', line 24 def id @id end |
#max_occurs ⇒ Integer
28 29 30 |
# File 'lib/term_utils/ap/article.rb', line 28 def max_occurs @max_occurs end |
#min_occurs ⇒ Integer
26 27 28 |
# File 'lib/term_utils/ap/article.rb', line 26 def min_occurs @min_occurs end |
#type ⇒ Symbol
Returns ‘:integer`, `:string`.
30 31 32 |
# File 'lib/term_utils/ap/article.rb', line 30 def type @type end |
Instance Method Details
#finalize!(opts = {}) ⇒ nil
Finalizes this one. Internal use.
51 52 53 54 55 56 57 58 59 |
# File 'lib/term_utils/ap/article.rb', line 51 def finalize!(opts = {}) raise TermUtils::AP::SyntaxError, 'min_occurs must be equal or greater than 0' if !@min_occurs.is_a?(Integer) || (@min_occurs < 0) raise TermUtils::AP::SyntaxError, 'max_occurs must be equal or greater than min_occurs' if occur_bounded? && (@max_occurs < @min_occurs) unless @id opts[:anonymous] += 1 @id = "anonymous#{opts[:anonymous]}".intern end end |
#multiple_occurs? ⇒ Boolean
Tests whether this one has mutiple occurs.
63 64 65 |
# File 'lib/term_utils/ap/article.rb', line 63 def multiple_occurs? (@max_occurs == nil) || (@max_occurs.is_a?(Integer) && (@max_occurs > 1)) end |
#occur_bounded? ⇒ Boolean
Tests whether the number of occurs is fixed.
69 70 71 |
# File 'lib/term_utils/ap/article.rb', line 69 def occur_bounded? (@max_occurs != nil) && @max_occurs.is_a?(Integer) end |