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

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

refs #73

File size: 2.8 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 OperatorKind
71 OP_EQ = 2001
72 OP_NE = 2002
73 OP_LE = 2003
74 OP_LT = 2004
75 OP_GE = 2005
76 OP_GT = 2006
77 OP_MATCHES = 2007
78
79 OP_NOT = 2010
80 OP_AND = 2011
81 OP_OR = 2012
82 OP_XOR = 2013
83 OP_IMPLIES = 2014
84 OP_FOR_ALL = 2015
85 OP_EXISTS = 2016
86
87 OP_PLUS = 2020
88 OP_MINUS = 2021
89 OP_MULTIPLY = 2022
90 OP_DIVIDE = 2023
91 OP_EXP = 2024
92
93 attr_reader :value
94
95 def initialize(args = { })
96 self.value = args[:value]
97 end
98
99 def value=(value)
100 unless OperatorKind.valid_operator? value
101 raise ArgumentError, 'invalid value'
102 end
103 @value = value
104 end
105
106 def self.valid_operator?(value)
107 if value >= OP_EQ && value <= OP_EXP
108 return true
109 else
110 return false
111 end
112 end
113 end
114 end # of Assetion
115 end # of Archtype
116 end #of AM
117end # of OpenEHR
Note: See TracBrowser for help on using the repository browser.