Name | Total Lines | Lines of Code | Total Coverage | Code Coverage |
---|---|---|---|---|
ddl/DDL.rb | 139 | 88 | 32.37%
|
38.64%
|
Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.
1 require 'nokogiri' |
2 require 'open-uri' |
3 require 'uuid' |
4 |
5 require File.expand_path(File.dirname(__FILE__) + '/DDL_module.rb') |
6 require File.expand_path(File.dirname(__FILE__) + '/DDL_element.rb') |
7 require File.expand_path(File.dirname(__FILE__) + '/device_description.rb') |
8 require File.expand_path(File.dirname(__FILE__) + '/language_set.rb') |
9 require File.expand_path(File.dirname(__FILE__) + '/behavior_set.rb') |
10 |
11 module ACN |
12 module DDL |
13 # Architecture for Control Networks |
14 # Device Description Language Interface |
15 # |
16 # The DDL class encapsulates the data for DDL Modules. |
17 # Modules consist of devices,languagesets and behavioursets |
18 # It can combine the root elements of several DDL files |
19 # |
20 # Loading a DDL file flattens the layering or nesting of included DDL elements. |
21 # The ACN specification states that "Nesting of DDL elements contains no meaning." |
22 # |
23 class DDL |
24 |
25 # The currently supported version of DDL |
26 SupportedVersion = "1.0" |
27 |
28 # The DDL file version used to create this DDL |
29 # Cannot be > Supported Version |
30 attr_reader :version |
31 |
32 # The array of device descriptions |
33 attr_accessor :devices |
34 |
35 # The array of behaviours |
36 attr_accessor :behavior_sets |
37 |
38 # The array of language sets |
39 attr_accessor :language_sets |
40 |
41 # An array of errors from the Nokogiri parser |
42 attr_accessor :errors |
43 |
44 def initialize(v = SupportedVersion) |
45 @version = v |
46 @devices = [] |
47 @language_sets = [] |
48 @behavior_sets = [] |
49 @errors = [] |
50 end |
51 |
52 def version=(new_version) |
53 if new_version.to_s > SupportedVersion |
54 raise "Cannot support this DDL version. Current version is #{SupportedVersion}." |
55 else |
56 @version = new_version.to_s |
57 end |
58 end |
59 |
60 # Create a new DDL object form a file or io |
61 def self.from_xml(xml) |
62 doc = Nokogiri::XML::Document.parse(xml) |
63 ddl = DDL.new(doc.root["version"]) |
64 ddl.add_elements(doc) |
65 return ddl |
66 end |
67 |
68 # Read new Modules in from an IO or string object via Nokogiri |
69 # xml can be any io or XML string or URI |
70 def read(xml) |
71 add_elements(Nokogiri::XML.parse(xml)) |
72 end |
73 |
74 # Write this DDL to an IO |
75 def write(xml) |
76 end |
77 |
78 # Add elements to the DDL |
79 def add_elements(doc) |
80 @errors += doc.errors |
81 |
82 doc.xpath('.//device').each do |xml| |
83 @devices << DeviceDescription.from_nokogiri(self, xml) |
84 end |
85 |
86 doc.xpath('.//languageset').each do |xml| |
87 @language_sets << LanguageSet.from_nokogiri(self, xml) |
88 end |
89 |
90 doc.xpath('.//behaviorset').each do |xml| |
91 @behavior_sets << BehaviorSet.from_nokogiri(self, xml) |
92 end |
93 end |
94 |
95 def modules |
96 @devices + @behavior_sets + @language_sets |
97 end |
98 |
99 def get_module(uuid) |
100 modules.find{|m| m.uuid == uuid} |
101 end |
102 |
103 def add_device_description(opts = {}) |
104 devices << DeviceDescription.new(self,opts) |
105 end |
106 |
107 def add_behavior_set(opts ={}) |
108 behavior_sets << BehaviorSet.new(self,opts) |
109 end |
110 |
111 def add_language_set(opts ={}) |
112 language_sets << LanguageSet.new(self,opts) |
113 end |
114 |
115 def get_device_description(uuid) |
116 devices.find{|d| d.uuid == uuid} |
117 end |
118 |
119 def get_behavior_set(uuid) |
120 behavior_sets.find{|d| d.uuid == uuid} |
121 end |
122 |
123 def get_language_set(uuid) |
124 language_sets.find{|d| d.uuid == uuid} |
125 end |
126 |
127 def get_language(uuid, locale = Locale.current) |
128 get_language_set(uuid).languages[locale] |
129 end |
130 |
131 def translate(key,lang,uuid) |
132 langset = get_language_set(uuid) |
133 langset.translate(key,lang) |
134 end |
135 |
136 end |
137 |
138 end |
139 end |
Generated on 2010-03-16 15:14:05 +1000 with rcov 0.9.2.1