Class: TermUtils::AP::Parameter

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

Overview

Represents a Parameter.

Instance Attribute Summary collapse

Attributes inherited from Element

#flags, #id, #max_occurs, #min_occurs

Instance Method Summary collapse

Methods inherited from Element

#define_flag, #flagged?, #multiple_occurs?, #occur_bounded?

Constructor Details

#initialize(opts = {}) ⇒ Parameter

Constructs a new Parameter.

Parameters:

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

Options Hash (opts):

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

    Default value is ‘0`.

  • :max_occurs (Integer)

    Default value is ‘1`.



29
30
31
32
33
34
35
# File 'lib/term_utils/ap/parameter.rb', line 29

def initialize(opts = {})
  @id = opts.fetch(:id, nil)
  @min_occurs = opts.fetch(:min_occurs, 0)
  @max_occurs = opts.fetch(:max_occurs, 1)
  @flags = []
  @articles = []
end

Instance Attribute Details

#articlesArray<TermUtils::AP::Article>

Returns:



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

def articles
  @articles
end

Instance Method Details

#define_article(opts = {}, &block) ⇒ TermUtils::AP::Article

Adds a new Article to this one.

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)

Returns:



62
63
64
65
66
67
# File 'lib/term_utils/ap/parameter.rb', line 62

def define_article(opts = {}, &block)
  new_article = TermUtils::AP::Article.new(opts)
  @articles << new_article
  block.call(new_article) if block
  new_article
end

#fetch_articlesArray<TermUtils::AP::Article>

Fetches all articles.

Returns:



70
71
72
# File 'lib/term_utils/ap/parameter.rb', line 70

def fetch_articles
  @articles.collect { |a| a.dup }
end

#finalize!(opts = {}) ⇒ nil

Finalizes this one. Internal use.

Returns:

  • (nil)


48
49
50
51
52
53
# File 'lib/term_utils/ap/parameter.rb', line 48

def finalize!(opts = {})
  super
  @articles.each do |a|
    a.finalize!(opts)
  end
end

#initialize_dup(other) ⇒ Object

For dup method.



37
38
39
40
41
42
43
44
45
# File 'lib/term_utils/ap/parameter.rb', line 37

def initialize_dup(other)
  if other.articles
    @articles = []
    other.articles.each do |a|
      @articles << a.dup
    end
  end
  super
end