Class: Stupidedi::Schema::SimpleElementUse

Inherits:
AbstractElementUse show all
Defined in:
lib/stupidedi/schema/element_use.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractElementUse

#composite?, #empty, #value

Methods included from Inspect

#inspect

Methods inherited from AbstractUse

#composite?, #definition?, #element?, #functional_group?, #interchange?, #loop?, #repeated?, #segment?, #table?, #transaction_set?, #usage?

Constructor Details

#initialize(definition, requirement, repeat_count, allowed_values, parent) ⇒ SimpleElementUse


56
57
58
59
60
61
62
63
64
65
# File 'lib/stupidedi/schema/element_use.rb', line 56

def initialize(definition, requirement, repeat_count, allowed_values, parent)
  @definition, @requirement, @repeat_count, @allowed_values, @parent =
    definition, requirement, repeat_count, allowed_values, parent

  # Delay re-parenting until the entire definition tree has a root
  # to prevent unnecessarily copying objects
  unless parent.nil?
    @definition = @definition.copy(:parent => self)
  end
end

Instance Attribute Details

#allowed_valuesAbstractSet (readonly)


51
52
53
# File 'lib/stupidedi/schema/element_use.rb', line 51

def allowed_values
  @allowed_values
end

#definitionSimpleElementDef (readonly)


42
43
44
# File 'lib/stupidedi/schema/element_use.rb', line 42

def definition
  @definition
end

#parentSegmentDef (readonly)


54
55
56
# File 'lib/stupidedi/schema/element_use.rb', line 54

def parent
  @parent
end

#repeat_countRepeatCount (readonly)


48
49
50
# File 'lib/stupidedi/schema/element_use.rb', line 48

def repeat_count
  @repeat_count
end

#requirementElementReq (readonly)


45
46
47
# File 'lib/stupidedi/schema/element_use.rb', line 45

def requirement
  @requirement
end

Instance Method Details

#code_listsAbstractSet<CodeList>


97
98
99
100
101
102
103
# File 'lib/stupidedi/schema/element_use.rb', line 97

def code_lists
  if forbidden?
    Sets.empty
  else
    @definition.code_lists(@allowed_values)
  end
end

#component?Boolean


92
93
94
# File 'lib/stupidedi/schema/element_use.rb', line 92

def component?
  false
end

#copy(changes = {}) ⇒ SimpleElementUse


68
69
70
71
72
73
74
75
# File 'lib/stupidedi/schema/element_use.rb', line 68

def copy(changes = {})
  SimpleElementUse.new \
    changes.fetch(:definition, @definition),
    changes.fetch(:requirement, @requirement),
    changes.fetch(:repeat_count, @repeat_count),
    changes.fetch(:allowed_values, @allowed_values),
    changes.fetch(:parent, @parent)
end

#parse(string) ⇒ SimpleElementVal


78
79
80
# File 'lib/stupidedi/schema/element_use.rb', line 78

def parse(string)
  definition.parse(string, self)
end

#pretty_print(q)


106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/stupidedi/schema/element_use.rb', line 106

def pretty_print(q)
  q.text("SimpleElementUse")
  q.group(2, "(", ")") do
    q.breakable ""
    q.pp @definition
    q.text ","

    q.breakable
    q.pp @requirement
    q.text ","

    q.breakable
    q.pp @repeat_count
  end
end

#repeatable?Boolean


82
83
84
# File 'lib/stupidedi/schema/element_use.rb', line 82

def repeatable?
  @repeat_count.try{|r| r.include?(2) }
end

#simple?Boolean


87
88
89
# File 'lib/stupidedi/schema/element_use.rb', line 87

def simple?
  true
end