Class: TermUtils::AP::Article

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

Overview

Represents a Article.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Article

Constructs a new Article.

Parameters:

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

Options Hash (opts):

  • :id (Symbol)
  • :min_occurs (Integer)

    Default value is `1`.

  • :max_occurs (Integer)

    Default value is `1`.

  • :type (Symbol)

    `:integer`, `:string`.

  • :format (Symbol)


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

#formatString

Returns `%d`, `%s`.

Returns:

  • (String)

    `%d`, `%s`.



31
32
33
# File 'lib/term_utils/ap/article.rb', line 31

def format
  @format
end

#idSymbol

Returns:

  • (Symbol)


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

def id
  @id
end

#max_occursInteger

Returns:

  • (Integer)


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

def max_occurs
  @max_occurs
end

#min_occursInteger

Returns:

  • (Integer)


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

def min_occurs
  @min_occurs
end

#typeSymbol

Returns `:integer`, `:string`

Returns:

  • (Symbol)

    `: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.

Returns:

  • (nil)

Raises:



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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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