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 are fixed.
Constructor Details
#initialize(opts = {}) ⇒ Article
Constructs a new Article.
39 40 41 42 43 44 45 |
# File 'lib/term_utils/ap/article.rb', line 39 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`.
31 32 33 |
# File 'lib/term_utils/ap/article.rb', line 31 def format @format end |
#id ⇒ Symbol
23 24 25 |
# File 'lib/term_utils/ap/article.rb', line 23 def id @id end |
#max_occurs ⇒ Integer
27 28 29 |
# File 'lib/term_utils/ap/article.rb', line 27 def max_occurs @max_occurs end |
#min_occurs ⇒ Integer
25 26 27 |
# File 'lib/term_utils/ap/article.rb', line 25 def min_occurs @min_occurs end |
#type ⇒ Symbol
Returns `:integer`, `:string`
29 30 31 |
# File 'lib/term_utils/ap/article.rb', line 29 def type @type end |
Instance Method Details
#finalize!(opts = {}) ⇒ nil
Finalizes this one. Internal use.
48 49 50 51 52 53 54 55 |
# File 'lib/term_utils/ap/article.rb', line 48 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 |
#multiple_occurs? ⇒ Boolean
Tests whether this one has mutiple occurs.
58 59 60 |
# File 'lib/term_utils/ap/article.rb', line 58 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.
63 64 65 |
# File 'lib/term_utils/ap/article.rb', line 63 def occur_bounded? (@max_occurs != nil) && (@max_occurs != :infinity) && (@max_occurs.is_a? Integer) end |