Module: XSD::MinMaxOccurs

Included in:
All, Any, Choice, Element, Group, Sequence
Defined in:
lib/xsd/shared/min_max_occurs.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#max_occursObject

Optional. Specifies the maximum number of times the choice element can occur in the parent element. The value can be any number >= 0, or if you want to set no limit on the maximum number, use the value “unbounded”. Default value is 1

Returns:

  • Integer, Symbol



15
16
17
18
# File 'lib/xsd/shared/min_max_occurs.rb', line 15

def self.included(obj)
  obj.property :minOccurs, :integer, default: 1
  obj.property :maxOccurs, :integer, default: 1
end

#min_occursObject

Optional. Specifies the minimum number of times the choice element can occur in the parent the element. The value can be any number >= 0. Default value is 1

Returns:

  • Integer



# File 'lib/xsd/shared/min_max_occurs.rb', line 5

Class Method Details

.included(obj) ⇒ Object

Optional. Specifies the maximum number of times the choice element can occur in the parent element. The value can be any number >= 0, or if you want to set no limit on the maximum number, use the value “unbounded”. Default value is 1

Returns:

  • Integer, Symbol



15
16
17
18
# File 'lib/xsd/shared/min_max_occurs.rb', line 15

def self.included(obj)
  obj.property :minOccurs, :integer, default: 1
  obj.property :maxOccurs, :integer, default: 1
end

Instance Method Details

#computed_max_occursObject

Compute actual max_occurs accounting parents

Returns:

  • Integer, Symbol



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/xsd/shared/min_max_occurs.rb', line 22

def computed_max_occurs
  @computed_max_occurs ||= if parent.is_a?(MinMaxOccurs)
                             if max_occurs == :unbounded || parent.computed_max_occurs == :unbounded
                               :unbounded
                             else
                               [max_occurs, parent.computed_max_occurs].max
                             end
                           else
                             max_occurs
                           end
end

#computed_min_occursObject

Compute actual min_occurs accounting parents

Returns:

  • Integer



36
37
38
39
40
41
42
43
44
# File 'lib/xsd/shared/min_max_occurs.rb', line 36

def computed_min_occurs
  @computed_min_occurs ||= if parent.is_a?(Choice)
                             0
                           elsif parent.is_a?(MinMaxOccurs)
                             [min_occurs, parent.computed_min_occurs].min
                           else
                             min_occurs
                           end
end

#multiple?Boolean

Determine if element may occur multiple times

Returns:

  • (Boolean)

    Boolean



48
49
50
# File 'lib/xsd/shared/min_max_occurs.rb', line 48

def multiple?
  max_occurs == :unbounded || max_occurs > 1
end

#multiple_allowed?Boolean

Determine if element may occur multiple times, accounting parents

Returns:

  • (Boolean)

    Boolean



54
55
56
# File 'lib/xsd/shared/min_max_occurs.rb', line 54

def multiple_allowed?
  computed_max_occurs == :unbounded || computed_max_occurs > 1
end