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)


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

#formatString

Returns `%d`, `%s`.

Returns:

  • (String)

    `%d`, `%s`.



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

def format
  @format
end

#idSymbol

Returns:

  • (Symbol)


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

def id
  @id
end

#max_occursInteger

Returns:

  • (Integer)


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

def max_occurs
  @max_occurs
end

#min_occursInteger

Returns:

  • (Integer)


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

def min_occurs
  @min_occurs
end

#typeSymbol

Returns `:integer`, `:string`.

Returns:

  • (Symbol)

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

Returns:

  • (nil)

Raises:



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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


69
70
71
# File 'lib/term_utils/ap/article.rb', line 69

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