source: ruby/trunk/lib/open_ehr/am/archetype/assertion.rb@ 389

Last change on this file since 389 was 389, checked in by KOBAYASHI, Shinji, 14 years ago

refs #73
A happy new year!

File size: 3.5 KB
Line 
1module OpenEHR
2 module AM
3 module Archetype
4 module Assertion
5 class Assertion
6 attr_reader :expression, :tag
7 attr_accessor :string_expression, :variables
8
9 def initialize(args = { })
10 self.expression = args[:expression]
11 self.tag = args[:tag]
12 self.string_expression = args[:string_expression]
13 self.variables = args[:variables]
14 end
15
16 def expression=(expression)
17 if expression.nil? or expression.type.upcase != 'BOOLEAN'
18 raise ArgumentError, 'invalid expression'
19 end
20 @expression = expression
21 end
22
23 def tag=(tag)
24 if !tag.nil? && tag.empty?
25 raise ArgumentError, 'tag should not be empty'
26 end
27 @tag = tag
28 end
29 end
30
31 class ExprItem
32 attr_reader :type
33
34 def initialize(args = { })
35 self.type = args[:type]
36 end
37
38 def type=(type)
39 if type.nil? or type.empty?
40 raise ArgumentError, 'type is mandatory'
41 end
42 @type = type
43 end
44 end
45
46 class ExprLeaf < ExprItem
47 attr_reader :item, :reference_type
48
49 def initialize(args = { })
50 super
51 self.item = args[:item]
52 self.reference_type = args[:reference_type]
53 end
54
55 def item=(item)
56 if item.nil?
57 raise ArgumentError, 'item is mandatory'
58 end
59 @item = item
60 end
61
62 def reference_type=(reference_type)
63 if reference_type.nil?
64 raise ArgumentError, 'reference_type is mandatory'
65 end
66 @reference_type = reference_type
67 end
68 end
69
70 class ExprOperator < ExprItem
71 attr_accessor :operator, :precedence_overridden
72
73 def initialize(args = { })
74 super
75 self.operator = args[:operator]
76 self.precedence_overridden = args[:precedence_overridden]
77 end
78 end
79
80 class ExprUnaryOperator < ExprOperator
81 attr_reader :operand
82
83 def initialize(args = { })
84 super
85 self.operand = args[:operand]
86 end
87
88 def operand=(operand)
89 if operand.nil?
90 raise ArgumentError, 'operand is mandatory'
91 end
92 @operand = operand
93 end
94 end
95
96 class OperatorKind
97 OP_EQ = 2001
98 OP_NE = 2002
99 OP_LE = 2003
100 OP_LT = 2004
101 OP_GE = 2005
102 OP_GT = 2006
103 OP_MATCHES = 2007
104
105 OP_NOT = 2010
106 OP_AND = 2011
107 OP_OR = 2012
108 OP_XOR = 2013
109 OP_IMPLIES = 2014
110 OP_FOR_ALL = 2015
111 OP_EXISTS = 2016
112
113 OP_PLUS = 2020
114 OP_MINUS = 2021
115 OP_MULTIPLY = 2022
116 OP_DIVIDE = 2023
117 OP_EXP = 2024
118
119 attr_reader :value
120
121 def initialize(args = { })
122 self.value = args[:value]
123 end
124
125 def value=(value)
126 unless OperatorKind.valid_operator? value
127 raise ArgumentError, 'invalid value'
128 end
129 @value = value
130 end
131
132 def self.valid_operator?(value)
133 if value >= OP_EQ && value <= OP_EXP
134 return true
135 else
136 return false
137 end
138 end
139 end
140 end # of Assetion
141 end # of Archtype
142 end #of AM
143end # of OpenEHR
Note: See TracBrowser for help on using the repository browser.