source: ruby/branches/0.5/lib/open_ehr/rm/data_types/encapsulated.rb@ 238

Last change on this file since 238 was 238, checked in by KOBAYASHI, Shinji, 12 years ago

dv_parsable modified

File size: 3.0 KB
Line 
1# OpenEHR::RM::Data_Types::Encapsulated
2# http://www.openehr.org/svn/specification/TAGS/Release-1.0.2/publishing/architecture/computable/UML/uml_start_view.html
3# refs #51
4require 'rubygems'
5require 'locale/info'
6
7module OpenEHR
8 module RM
9 module DataTypes
10 module Encapsulated
11 class DvEncapsulated < OpenEHR::RM::DataTypes::Basic::DataValue
12 attr_reader :language, :charset
13
14 def initialize(args = {})
15 super(args)
16 self.charset = args[:charset]
17 self.language = args[:language]
18 end
19
20 def size
21 @value.size
22 end
23
24 def language=(language)
25 if !language.nil? &&
26 !Locale::Info.language_code?(language.code_string)
27 raise ArgumentError, 'invalid language code'
28 end
29 @language = language
30 end
31
32 def charset=(charset)
33 if !charset.nil? && !charset_valid?(charset.code_string)
34 raise ArgumentError, 'invalid charset'
35 end
36 @charset = charset
37 end
38
39 private
40
41 def charset_valid?(charset)
42 result = false
43 open('lib/open_ehr/rm/data_types/charset.lst') do |file|
44 while line = file.gets
45 if charset == line.chomp
46 result = true
47 break
48 end
49 end
50 end
51 return result
52 end
53 end
54
55# media type http://www.iana.org/assignments/media-types/text/
56 class DvMultimedia < DvEncapsulated
57 attr_reader :media_type
58 attr_accessor :uri, :data, :compression_algorithm,
59 :integrity_check, :integrity_check_algorithm, :alternate_text
60 def initialize(charset, language, size, media_type, uri=nil,
61 data=nil, compression_algorithm=nil,
62 integrity_check=nil, integrity_check_algorithm=nil,
63 alternate_text=nil)
64 super(charset, language, size)
65 self.media_type = media_type
66 @uri = uri
67 @data = data
68 @compression_algorithm = compression_algorithm
69 @integrity_check = integrity_check
70 @integrity_check_algorithm = integrity_check_algorithm
71 @alternate_text = alternate_text
72 end
73 def media_type=(media_type)
74 if media_type.code_string.nil?
75 raise ArgumentError, 'media_type should not be nil'
76 end
77 @media_type = media_type
78 end
79 end
80
81 class DvParsable < DvEncapsulated
82 attr_reader :formalism
83
84 def initialize(args = {})
85 super(args)
86 self.formalism = args[:formalism]
87 end
88
89 def formalism=(formalism)
90 if formalism.nil? || formalism.empty?
91 raise ArgumentError, 'formalism is mandatory'
92 end
93 @formalism = formalism
94 end
95 end
96 end # of Encapsulated
97 end # of DataTypes
98 end # of RM
99end # of OpenEHR
Note: See TracBrowser for help on using the repository browser.