rubyang 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,917 @@
1
+ # coding: utf-8
2
+
3
+ require_relative 'model/parser'
4
+
5
+ module Rubyang
6
+ module Model
7
+ DataDefStmtList ||= %w( container leaf leaf-list list choice case augment uses anyxml )
8
+ DataNodeList ||= %w( container leaf leaf-list list anyxml )
9
+ SchemaNodeList ||= %w( container leaf leaf-list list choice case rpc input output notification anyxml )
10
+ TypeBodyStmtList ||= %w( range fraction-digits length pattern default enum leafref path require-instance identityref union bit position )
11
+
12
+ def schema_nodeid
13
+ "(?:#{absolute_schema_nodeid}|#{descendant_schema_nodeid})"
14
+ end
15
+ def absolute_schema_nodeid
16
+ "(?:(?:/#{node_identifier})+)"
17
+ end
18
+ def descendant_schema_nodeid
19
+ "(?:#{node_identifier}#{absolute_schema_nodeid})"
20
+ end
21
+ def node_identifier
22
+ "(?:(?:#{prefix}:)?#{identifier})"
23
+ end
24
+ def instance_identifier
25
+ "(?:(?:/#{node_identifier}(?:#{predicate})*)+)"
26
+ end
27
+ def predicate
28
+ "(?:\[#{wsp}*(?:#{predicate_expr}|#{pos})#{wsp}*\])"
29
+ end
30
+ def predicate_expr
31
+ "(?:(?:#{node_identifier}|[.])#{wsp}*=#{wsp}*(?:(?:#{dquote}[^#{dquote}]*#{dquote})|(?:#{squote}[^#{squote}]*#{squote})))"
32
+ end
33
+ def pos
34
+ '(?:[0-9]+)'
35
+ end
36
+ def prefix
37
+ "(?:#{identifier})"
38
+ end
39
+ def identifier
40
+ '(?:[a-zA-Z][a-zA-Z0-9._-]*)'
41
+ end
42
+ def dquote
43
+ '"'
44
+ end
45
+ def squote
46
+ "'"
47
+ end
48
+ def wsp
49
+ '(?:[ \t])'
50
+ end
51
+
52
+ class BaseStmt
53
+ def substatements
54
+ {}
55
+ end
56
+ def initialize substmts=[]
57
+ # raise if received susstatements has invalid substatement
58
+ substmts.each{ |s|
59
+ unless self.substatements.include? StmtMap.find( s.class ).intern
60
+ raise ArgumentError, "#{StmtMap.find( s.class )} is not #{self.class}'s substatement"
61
+ end
62
+ }
63
+ # raise if received susstatements does not satisfy defined substatements' cardinality
64
+ self.substatements.each{ |k, v|
65
+ unless v.include? substmts.select{ |s| StmtMap.find( s ).intern == k }.size
66
+ raise ArgumentError, "substatement #{StmtMap.find( k )} is not in #{self.class} #{k}'s cardinality"
67
+ end
68
+ }
69
+ # raise if received susstatements has invalid substatement class
70
+ substmts.each{ |s|
71
+ unless BaseStmt === s
72
+ raise ArgumentError, "#{s.class} is not Rubyang::Model's class"
73
+ end
74
+ }
75
+ @substmts = substmts
76
+ end
77
+ def substmt substmt, strict: false
78
+ raise TypeError unless String === substmt
79
+ if strict
80
+ unless self.substatements[substmt.intern]
81
+ raise ArgumentError, "#{StmtMap.find( s ).class} is not #{self.class}'s substatement"
82
+ end
83
+ end
84
+ @substmts.select{ |_s| StmtMap.find( substmt ) === _s }
85
+ end
86
+ def substmts substmts, strict: false
87
+ raise TypeError unless Array === substmts
88
+ if strict
89
+ substmts.each{ |s|
90
+ unless self.substatements[s.intern]
91
+ raise ArgumentError, "#{StmtMap.find( s ).class} is not #{self.class}'s substatement"
92
+ end
93
+ }
94
+ end
95
+ @substmts.select{ |_s| substmts.find{ |s| StmtMap.find( s ) === _s } }
96
+ end
97
+ def has_substmt? substmt
98
+ unless self.substatements[substmt.intern]
99
+ raise ArgumentError, "#{StmtMap.find( substmt ).class} is not #{self.class}'s substatement"
100
+ end
101
+ if @substmts.find{ |s| StmtMap.find( substmt ) === s }
102
+ true
103
+ else
104
+ false
105
+ end
106
+ end
107
+ def schema_node_substmts
108
+ @substmts.select{ |s| SchemaNodeList.include? StmtMap.find( s ) }
109
+ end
110
+ def not_schema_node_substmts
111
+ @substmts.select{ |s| not SchemaNodeList.include? StmtMap.find( s ) }
112
+ end
113
+ def without_not_schema_node_substmts
114
+ self.class.new( self.arg, self.not_schema_node_substmts )
115
+ end
116
+ def to_yang level=0, pretty: false, indent: 2
117
+ str = ""
118
+ str += " " * indent * level if pretty
119
+ str += "#{StmtMap.find( self )} #{self.arg}"
120
+ if @substmts.size > 0
121
+ str += " {\n"
122
+ @substmts.each{ |s|
123
+ str += s.to_yang level+1, pretty: pretty, indent: indent
124
+ }
125
+ str += " " * indent * level if pretty
126
+ str += "}\n"
127
+ else
128
+ str += ";\n"
129
+ end
130
+ end
131
+ end
132
+
133
+ class NoArgStmt < BaseStmt
134
+ end
135
+
136
+ class ArgStmt < BaseStmt
137
+ def initialize arg, substmts=[]
138
+ super substmts
139
+ @arg = arg
140
+ unless valid_arg? arg
141
+ raise ArgumentError, "Invalid Argument: '#{arg}'"
142
+ end
143
+ end
144
+ def arg
145
+ @arg
146
+ end
147
+ def arg_regexp
148
+ '(?:.*)'
149
+ end
150
+ def valid_arg? arg
151
+ re = Regexp.new( "^#{arg_regexp}$" )
152
+ re === arg
153
+ end
154
+ end
155
+
156
+ class Module < ArgStmt
157
+ def substatements
158
+ {
159
+ :'anyxml' => 0..Float::INFINITY,
160
+ :'augment' => 0..Float::INFINITY,
161
+ :'choice' => 0..Float::INFINITY,
162
+ :'contact' => 0..1,
163
+ :'container' => 0..Float::INFINITY,
164
+ :'description' => 0..1,
165
+ :'deviation' => 0..Float::INFINITY,
166
+ :'extension' => 0..Float::INFINITY,
167
+ :'feature' => 0..Float::INFINITY,
168
+ :'grouping' => 0..Float::INFINITY,
169
+ :'identity' => 0..Float::INFINITY,
170
+ :'import' => 0..Float::INFINITY,
171
+ :'include' => 0..Float::INFINITY,
172
+ :'leaf' => 0..Float::INFINITY,
173
+ :'leaf-list' => 0..Float::INFINITY,
174
+ :'list' => 0..Float::INFINITY,
175
+ :'namespace' => 1..1,
176
+ :'notification' => 0..Float::INFINITY,
177
+ :'organization' => 0..1,
178
+ :'prefix' => 1..1,
179
+ :'reference' => 0..1,
180
+ :'revision' => 0..Float::INFINITY,
181
+ :'rpc' => 0..Float::INFINITY,
182
+ :'typedef' => 0..Float::INFINITY,
183
+ :'uses' => 0..Float::INFINITY,
184
+ :'yang-version' => 0..1,
185
+ }
186
+ end
187
+ end
188
+
189
+ class YangVersion < ArgStmt
190
+ end
191
+
192
+ class Namespace < ArgStmt
193
+ end
194
+
195
+ class Prefix < ArgStmt
196
+ end
197
+
198
+ class Import < ArgStmt
199
+ def substatements
200
+ {
201
+ :'prefix' => 1..1,
202
+ :'revision-date' => 0..1,
203
+ }
204
+ end
205
+ end
206
+
207
+ class RevisionDate < ArgStmt
208
+ end
209
+
210
+ class Include < ArgStmt
211
+ def substatements
212
+ {
213
+ :'revision-date' => 0..1,
214
+ }
215
+ end
216
+ end
217
+
218
+ class Organization < ArgStmt
219
+ end
220
+
221
+ class Contact < ArgStmt
222
+ end
223
+
224
+ class Revision < ArgStmt
225
+ def substatements
226
+ {
227
+ :'description' => 0..1,
228
+ :'reference' => 0..1,
229
+ }
230
+ end
231
+ end
232
+
233
+ class Submodule < ArgStmt
234
+ def substatements
235
+ {
236
+ :'anyxml' => 0..Float::INFINITY,
237
+ :'augment' => 0..Float::INFINITY,
238
+ :'belongs-to' => 1..1,
239
+ :'choice' => 0..Float::INFINITY,
240
+ :'contact' => 0..1,
241
+ :'container' => 0..Float::INFINITY,
242
+ :'description' => 0..1,
243
+ :'deviation' => 0..Float::INFINITY,
244
+ :'extension' => 0..Float::INFINITY,
245
+ :'feature' => 0..Float::INFINITY,
246
+ :'grouping' => 0..Float::INFINITY,
247
+ :'identity' => 0..Float::INFINITY,
248
+ :'import' => 0..Float::INFINITY,
249
+ :'include' => 0..Float::INFINITY,
250
+ :'leaf' => 0..Float::INFINITY,
251
+ :'leaf-list' => 0..Float::INFINITY,
252
+ :'list' => 0..Float::INFINITY,
253
+ :'notification' => 0..Float::INFINITY,
254
+ :'organization' => 0..1,
255
+ :'reference' => 0..1,
256
+ :'revision' => 0..Float::INFINITY,
257
+ :'rpc' => 0..Float::INFINITY,
258
+ :'typedef' => 0..Float::INFINITY,
259
+ :'uses' => 0..Float::INFINITY,
260
+ :'yang-version' => 0..1,
261
+ }
262
+ end
263
+ end
264
+
265
+ class BelongsTo < ArgStmt
266
+ def substatements
267
+ {
268
+ :'prefix' => 1..1,
269
+ }
270
+ end
271
+ end
272
+
273
+ class Typedef < ArgStmt
274
+ def substatements
275
+ {
276
+ :'default' => 0..1,
277
+ :'description' => 0..1,
278
+ :'reference' => 0..1,
279
+ :'status' => 0..1,
280
+ :'type' => 1..1,
281
+ :'units' => 0..1,
282
+ }
283
+ end
284
+ end
285
+
286
+ class Type < ArgStmt
287
+ def substatements
288
+ {
289
+ :'bit' => 0..Float::INFINITY,
290
+ :'enum' => 0..Float::INFINITY,
291
+ :'length' => 0..1,
292
+ :'path' => 0..1,
293
+ :'pattern' => 0..Float::INFINITY,
294
+ :'range' => 0..1,
295
+ :'require-instance' => 0..1,
296
+ :'type' => 0..Float::INFINITY,
297
+ :'fraction-digits' => 0..1,
298
+ :'base' => 0..1,
299
+ }
300
+ end
301
+ end
302
+
303
+ class Bit < ArgStmt
304
+ def substatements
305
+ {
306
+ :'position' => 0..1,
307
+ :'status' => 0..1,
308
+ :'description' => 0..1,
309
+ :'reference' => 0..1,
310
+ }
311
+ end
312
+ end
313
+
314
+ class Enum < ArgStmt
315
+ def substatements
316
+ {
317
+ :'value' => 0..1,
318
+ :'status' => 0..1,
319
+ :'description' => 0..1,
320
+ :'reference' => 0..1,
321
+ }
322
+ end
323
+ end
324
+
325
+ class Value < ArgStmt
326
+ end
327
+
328
+ class FractionDigits < ArgStmt
329
+ end
330
+
331
+ class Identityref < ArgStmt
332
+ end
333
+
334
+ class Leafref < ArgStmt
335
+ end
336
+
337
+ class Position < ArgStmt
338
+ end
339
+
340
+ class Union < ArgStmt
341
+ end
342
+
343
+ class Length < ArgStmt
344
+ def substatements
345
+ {
346
+ :'error-message' => 0..1,
347
+ :'error-app-tag' => 0..1,
348
+ :'description' => 0..1,
349
+ :'reference' => 0..1,
350
+ }
351
+ end
352
+ end
353
+
354
+ class Path < ArgStmt
355
+ end
356
+
357
+ class Pattern < ArgStmt
358
+ def substatements
359
+ {
360
+ :'error-message' => 0..1,
361
+ :'error-app-tag' => 0..1,
362
+ :'description' => 0..1,
363
+ :'reference' => 0..1,
364
+ }
365
+ end
366
+ end
367
+
368
+ class Range < ArgStmt
369
+ def substatements
370
+ {
371
+ :'error-message' => 0..1,
372
+ :'error-app-tag' => 0..1,
373
+ :'description' => 0..1,
374
+ :'reference' => 0..1,
375
+ }
376
+ end
377
+ end
378
+
379
+ class RequireInstance < ArgStmt
380
+ end
381
+
382
+ class Units < ArgStmt
383
+ end
384
+
385
+ class Default < ArgStmt
386
+ end
387
+
388
+ class Container < ArgStmt
389
+ def substatements
390
+ {
391
+ :'anyxml' => 0..Float::INFINITY,
392
+ :'choice' => 0..Float::INFINITY,
393
+ :'config' => 0..1,
394
+ :'container' => 0..Float::INFINITY,
395
+ :'description' => 0..1,
396
+ :'grouping' => 0..Float::INFINITY,
397
+ :'if-feature' => 0..Float::INFINITY,
398
+ :'leaf' => 0..Float::INFINITY,
399
+ :'leaf-list' => 0..Float::INFINITY,
400
+ :'list' => 0..Float::INFINITY,
401
+ :'must' => 0..Float::INFINITY,
402
+ :'presence' => 0..1,
403
+ :'reference' => 0..1,
404
+ :'status' => 0..1,
405
+ :'typedef' => 0..Float::INFINITY,
406
+ :'uses' => 0..Float::INFINITY,
407
+ :'when' => 0..1,
408
+ }
409
+ end
410
+ end
411
+
412
+ class Must < ArgStmt
413
+ def substatements
414
+ {
415
+ :'description' => 0..1,
416
+ :'error-app-tag' => 0..1,
417
+ :'error-message' => 0..1,
418
+ :'reference' => 0..1,
419
+ }
420
+ end
421
+ end
422
+
423
+ class ErrorMessage < ArgStmt
424
+ end
425
+
426
+ class ErrorAppTag < ArgStmt
427
+ end
428
+
429
+ class Presence < ArgStmt
430
+ end
431
+
432
+ class Leaf < ArgStmt
433
+ def substatements
434
+ {
435
+ :'config' => 0..1,
436
+ :'default' => 0..1,
437
+ :'description' => 0..1,
438
+ :'if-feature' => 0..Float::INFINITY,
439
+ :'mandatory' => 0..1,
440
+ :'must' => 0..Float::INFINITY,
441
+ :'reference' => 0..1,
442
+ :'status' => 0..1,
443
+ :'type' => 1..1,
444
+ :'units' => 0..1,
445
+ :'when' => 0..1,
446
+ }
447
+ end
448
+ end
449
+
450
+ class Mandatory < ArgStmt
451
+ end
452
+
453
+ class LeafList < ArgStmt
454
+ def substatements
455
+ {
456
+ :'config' => 0..1,
457
+ :'description' => 0..1,
458
+ :'if-feature' => 0..Float::INFINITY,
459
+ :'max-elements' => 0..1,
460
+ :'min-elements' => 0..1,
461
+ :'must' => 0..Float::INFINITY,
462
+ :'ordered-by' => 0..1,
463
+ :'reference' => 0..1,
464
+ :'status' => 0..1,
465
+ :'type' => 1..1,
466
+ :'units' => 0..1,
467
+ :'when' => 0..1,
468
+ }
469
+ end
470
+ end
471
+
472
+ class MinElements < ArgStmt
473
+ end
474
+
475
+ class MaxElements < ArgStmt
476
+ end
477
+
478
+ class OrderedBy < ArgStmt
479
+ end
480
+
481
+ class List < ArgStmt
482
+ def substatements
483
+ {
484
+ :'anyxml' => 0..Float::INFINITY,
485
+ :'choice' => 0..Float::INFINITY,
486
+ :'config' => 0..1,
487
+ :'container' => 0..Float::INFINITY,
488
+ :'description' => 0..1,
489
+ :'grouping' => 0..Float::INFINITY,
490
+ :'if-feature' => 0..Float::INFINITY,
491
+ :'key' => 0..1,
492
+ :'leaf' => 0..Float::INFINITY,
493
+ :'leaf-list' => 0..Float::INFINITY,
494
+ :'list' => 0..Float::INFINITY,
495
+ :'max-elements' => 0..1,
496
+ :'min-elements' => 0..1,
497
+ :'must' => 0..Float::INFINITY,
498
+ :'ordered-by' => 0..1,
499
+ :'reference' => 0..1,
500
+ :'status' => 0..1,
501
+ :'typedef' => 0..Float::INFINITY,
502
+ :'unique' => 0..Float::INFINITY,
503
+ :'uses' => 0..Float::INFINITY,
504
+ :'when' => 0..1,
505
+ }
506
+ end
507
+ end
508
+
509
+ class Key < ArgStmt
510
+ end
511
+
512
+ class Unique < ArgStmt
513
+ end
514
+
515
+ class Choice < ArgStmt
516
+ def substatements
517
+ {
518
+ :'anyxml' => 0..Float::INFINITY,
519
+ :'case' => 0..Float::INFINITY,
520
+ :'config' => 0..1,
521
+ :'container' => 0..Float::INFINITY,
522
+ :'default' => 0..1,
523
+ :'description' => 0..1,
524
+ :'if-feature' => 0..Float::INFINITY,
525
+ :'leaf' => 0..Float::INFINITY,
526
+ :'leaf-list' => 0..Float::INFINITY,
527
+ :'list' => 0..Float::INFINITY,
528
+ :'mandatory' => 0..1,
529
+ :'reference' => 0..1,
530
+ :'status' => 0..1,
531
+ :'when' => 0..1,
532
+ }
533
+ end
534
+ end
535
+
536
+ class Case < ArgStmt
537
+ def substatements
538
+ {
539
+ :'anyxml' => 0..Float::INFINITY,
540
+ :'choice' => 0..Float::INFINITY,
541
+ :'container' => 0..Float::INFINITY,
542
+ :'description' => 0..1,
543
+ :'if-feature' => 0..Float::INFINITY,
544
+ :'leaf' => 0..Float::INFINITY,
545
+ :'leaf-list' => 0..Float::INFINITY,
546
+ :'list' => 0..Float::INFINITY,
547
+ :'reference' => 0..1,
548
+ :'status' => 0..1,
549
+ :'uses' => 0..Float::INFINITY,
550
+ :'when' => 0..1,
551
+ }
552
+ end
553
+ end
554
+
555
+ class Anyxml < ArgStmt
556
+ def substatements
557
+ {
558
+ :'config' => 0..1,
559
+ :'description' => 0..1,
560
+ :'if-feature' => 0..Float::INFINITY,
561
+ :'mandatory' => 0..1,
562
+ :'must' => 0..Float::INFINITY,
563
+ :'reference' => 0..1,
564
+ :'status' => 0..1,
565
+ :'when' => 0..1,
566
+ }
567
+ end
568
+ end
569
+
570
+ class Grouping < ArgStmt
571
+ def substatements
572
+ {
573
+ :'anyxml' => 0..Float::INFINITY,
574
+ :'choice' => 0..Float::INFINITY,
575
+ :'container' => 0..Float::INFINITY,
576
+ :'description' => 0..1,
577
+ :'grouping' => 0..Float::INFINITY,
578
+ :'leaf' => 0..Float::INFINITY,
579
+ :'leaf-list' => 0..Float::INFINITY,
580
+ :'list' => 0..Float::INFINITY,
581
+ :'reference' => 0..1,
582
+ :'status' => 0..1,
583
+ :'typedef' => 0..Float::INFINITY,
584
+ :'uses' => 0..Float::INFINITY,
585
+ }
586
+ end
587
+ end
588
+
589
+ class Uses < ArgStmt
590
+ def substatements
591
+ {
592
+ :'augment' => 0..1,
593
+ :'description' => 0..1,
594
+ :'if-feature' => 0..Float::INFINITY,
595
+ :'refine' => 0..1,
596
+ :'reference' => 0..1,
597
+ :'status' => 0..1,
598
+ :'when' => 0..1,
599
+ }
600
+ end
601
+ end
602
+
603
+ class Refine < ArgStmt
604
+ def substatements
605
+ {
606
+ :'config' => 0..1,
607
+ :'default' => 0..1,
608
+ :'description' => 0..1,
609
+ :'mandatory' => 0..1,
610
+ :'max-elements' => 0..1,
611
+ :'min-elements' => 0..1,
612
+ :'must' => 0..Float::INFINITY,
613
+ :'presence' => 0..1,
614
+ :'reference' => 0..1,
615
+ :'status' => 0..1,
616
+ :'when' => 0..1,
617
+ }
618
+ end
619
+ end
620
+
621
+ class Rpc < ArgStmt
622
+ def substatements
623
+ {
624
+ :'description' => 0..1,
625
+ :'grouping' => 0..Float::INFINITY,
626
+ :'if-feature' => 0..Float::INFINITY,
627
+ :'input' => 0..1,
628
+ :'output' => 0..1,
629
+ :'reference' => 0..1,
630
+ :'status' => 0..1,
631
+ :'typedef' => 0..Float::INFINITY,
632
+ }
633
+ end
634
+ end
635
+
636
+ class Input < NoArgStmt
637
+ def substatements
638
+ {
639
+ :'anyxml' => 0..Float::INFINITY,
640
+ :'choice' => 0..Float::INFINITY,
641
+ :'container' => 0..Float::INFINITY,
642
+ :'grouping' => 0..Float::INFINITY,
643
+ :'leaf' => 0..Float::INFINITY,
644
+ :'leaf-list' => 0..Float::INFINITY,
645
+ :'list' => 0..Float::INFINITY,
646
+ :'typedef' => 0..Float::INFINITY,
647
+ :'uses' => 0..Float::INFINITY,
648
+ }
649
+ end
650
+ end
651
+
652
+ class Output < NoArgStmt
653
+ def substatements
654
+ {
655
+ :'anyxml' => 0..Float::INFINITY,
656
+ :'choice' => 0..Float::INFINITY,
657
+ :'container' => 0..Float::INFINITY,
658
+ :'grouping' => 0..Float::INFINITY,
659
+ :'leaf' => 0..Float::INFINITY,
660
+ :'leaf-list' => 0..Float::INFINITY,
661
+ :'list' => 0..Float::INFINITY,
662
+ :'typedef' => 0..Float::INFINITY,
663
+ :'uses' => 0..Float::INFINITY,
664
+ }
665
+ end
666
+ end
667
+
668
+ class Notification < ArgStmt
669
+ def substatements
670
+ {
671
+ :'anyxml' => 0..Float::INFINITY,
672
+ :'choice' => 0..Float::INFINITY,
673
+ :'container' => 0..Float::INFINITY,
674
+ :'description' => 0..1,
675
+ :'grouping' => 0..Float::INFINITY,
676
+ :'if-feature' => 0..Float::INFINITY,
677
+ :'leaf' => 0..Float::INFINITY,
678
+ :'leaf-list' => 0..Float::INFINITY,
679
+ :'list' => 0..Float::INFINITY,
680
+ :'reference' => 0..1,
681
+ :'status' => 0..1,
682
+ :'typedef' => 0..Float::INFINITY,
683
+ :'uses' => 0..Float::INFINITY,
684
+ }
685
+ end
686
+ end
687
+
688
+ class Augment < ArgStmt
689
+ def substatements
690
+ {
691
+ :'anyxml' => 0..Float::INFINITY,
692
+ :'case' => 0..Float::INFINITY,
693
+ :'choice' => 0..Float::INFINITY,
694
+ :'container' => 0..Float::INFINITY,
695
+ :'description' => 0..1,
696
+ :'if-feature' => 0..Float::INFINITY,
697
+ :'leaf' => 0..Float::INFINITY,
698
+ :'leaf-list' => 0..Float::INFINITY,
699
+ :'list' => 0..Float::INFINITY,
700
+ :'reference' => 0..1,
701
+ :'status' => 0..1,
702
+ :'uses' => 0..Float::INFINITY,
703
+ :'when' => 0..1,
704
+ }
705
+ end
706
+ end
707
+
708
+ class Identity < ArgStmt
709
+ def substatements
710
+ {
711
+ :'base' => 0..1,
712
+ :'description' => 0..1,
713
+ :'reference' => 0..1,
714
+ :'status' => 0..1,
715
+ }
716
+ end
717
+ end
718
+
719
+ class Base < ArgStmt
720
+ end
721
+
722
+ class Extension < ArgStmt
723
+ def substatements
724
+ {
725
+ :'argument' => 0..1,
726
+ :'description' => 0..1,
727
+ :'reference' => 0..1,
728
+ :'status' => 0..1,
729
+ }
730
+ end
731
+ end
732
+
733
+ class Argument < ArgStmt
734
+ def substatements
735
+ {
736
+ :'yin-element' => 0..1,
737
+ }
738
+ end
739
+ end
740
+
741
+ class YinElement < ArgStmt
742
+ end
743
+
744
+ class ConformanceRelated < ArgStmt
745
+ end
746
+
747
+ class Feature < ArgStmt
748
+ def substatements
749
+ {
750
+ :'description' => 0..1,
751
+ :'if-feature' => 0..Float::INFINITY,
752
+ :'reference' => 0..1,
753
+ :'status' => 0..1,
754
+ }
755
+ end
756
+ end
757
+
758
+ class IfFeature < ArgStmt
759
+ end
760
+
761
+ class Deviation < ArgStmt
762
+ def substatements
763
+ {
764
+ :'description' => 0..1,
765
+ :'deviate' => 1..Float::INFINITY,
766
+ :'reference' => 0..1,
767
+ }
768
+ end
769
+ end
770
+
771
+ class Deviate < ArgStmt
772
+ def substatements
773
+ {
774
+ :'config' => 0..1,
775
+ :'default' => 0..1,
776
+ :'mandatory' => 0..1,
777
+ :'max-elements' => 0..1,
778
+ :'min-elements' => 0..1,
779
+ :'must' => 0..Float::INFINITY,
780
+ :'type' => 0..1,
781
+ :'unique' => 0..Float::INFINITY,
782
+ :'units' => 0..1,
783
+ }
784
+ end
785
+ end
786
+
787
+ class Config < ArgStmt
788
+ end
789
+
790
+ class Status < ArgStmt
791
+ end
792
+
793
+ class Description < ArgStmt
794
+ end
795
+
796
+ class Reference < ArgStmt
797
+ end
798
+
799
+ class When < ArgStmt
800
+ def substatements
801
+ {
802
+ :'description' => 0..1,
803
+ :'reference' => 0..1,
804
+ }
805
+ end
806
+ end
807
+
808
+ class StmtMap
809
+ @@stmt_map = [
810
+ { :name => 'anyxml', :class => Rubyang::Model::Anyxml },
811
+ { :name => 'augment', :class => Rubyang::Model::Augment },
812
+ { :name => 'argument', :class => Rubyang::Model::Argument },
813
+ { :name => 'base', :class => Rubyang::Model::Base },
814
+ { :name => 'belongs-to', :class => Rubyang::Model::BelongsTo },
815
+ { :name => 'bit', :class => Rubyang::Model::Bit },
816
+ { :name => 'case', :class => Rubyang::Model::Case },
817
+ { :name => 'choice', :class => Rubyang::Model::Choice },
818
+ { :name => 'config', :class => Rubyang::Model::Config },
819
+ { :name => 'contact', :class => Rubyang::Model::Contact },
820
+ { :name => 'container', :class => Rubyang::Model::Container },
821
+ { :name => 'default', :class => Rubyang::Model::Default },
822
+ { :name => 'description', :class => Rubyang::Model::Description },
823
+ { :name => 'deviation', :class => Rubyang::Model::Deviation },
824
+ { :name => 'deviate', :class => Rubyang::Model::Deviate },
825
+ { :name => 'enum', :class => Rubyang::Model::Enum },
826
+ { :name => 'error-app-tag', :class => Rubyang::Model::ErrorAppTag },
827
+ { :name => 'error-message', :class => Rubyang::Model::ErrorMessage },
828
+ { :name => 'extension', :class => Rubyang::Model::Extension },
829
+ { :name => 'feature', :class => Rubyang::Model::Feature },
830
+ { :name => 'fraction-digits', :class => Rubyang::Model::FractionDigits },
831
+ { :name => 'grouping', :class => Rubyang::Model::Grouping },
832
+ { :name => 'identity', :class => Rubyang::Model::Identity },
833
+ { :name => 'identityref', :class => Rubyang::Model::Identityref },
834
+ { :name => 'if-feature', :class => Rubyang::Model::IfFeature },
835
+ { :name => 'import', :class => Rubyang::Model::Import },
836
+ { :name => 'include', :class => Rubyang::Model::Include },
837
+ { :name => 'input', :class => Rubyang::Model::Input },
838
+ { :name => 'key', :class => Rubyang::Model::Key },
839
+ { :name => 'leaf', :class => Rubyang::Model::Leaf },
840
+ { :name => 'leaf-list', :class => Rubyang::Model::LeafList },
841
+ { :name => 'leafref', :class => Rubyang::Model::Leafref },
842
+ { :name => 'length', :class => Rubyang::Model::Length },
843
+ { :name => 'list', :class => Rubyang::Model::List },
844
+ { :name => 'mandatory', :class => Rubyang::Model::Mandatory },
845
+ { :name => 'max-elements', :class => Rubyang::Model::MaxElements },
846
+ { :name => 'min-elements', :class => Rubyang::Model::MinElements },
847
+ { :name => 'module', :class => Rubyang::Model::Module },
848
+ { :name => 'must', :class => Rubyang::Model::Must },
849
+ { :name => 'namespace', :class => Rubyang::Model::Namespace },
850
+ { :name => 'notification', :class => Rubyang::Model::Notification },
851
+ { :name => 'ordered-by', :class => Rubyang::Model::OrderedBy },
852
+ { :name => 'organization', :class => Rubyang::Model::Organization },
853
+ { :name => 'output', :class => Rubyang::Model::Output },
854
+ { :name => 'path', :class => Rubyang::Model::Path },
855
+ { :name => 'pattern', :class => Rubyang::Model::Pattern },
856
+ { :name => 'position', :class => Rubyang::Model::Position },
857
+ { :name => 'prefix', :class => Rubyang::Model::Prefix },
858
+ { :name => 'presence', :class => Rubyang::Model::Presence },
859
+ { :name => 'range', :class => Rubyang::Model::Range },
860
+ { :name => 'reference', :class => Rubyang::Model::Reference },
861
+ { :name => 'refine', :class => Rubyang::Model::Refine },
862
+ { :name => 'revision', :class => Rubyang::Model::Revision },
863
+ { :name => 'revision-date', :class => Rubyang::Model::RevisionDate },
864
+ { :name => 'require-instance', :class => Rubyang::Model::RequireInstance },
865
+ { :name => 'rpc', :class => Rubyang::Model::Rpc },
866
+ { :name => 'status', :class => Rubyang::Model::Status },
867
+ { :name => 'type', :class => Rubyang::Model::Type },
868
+ { :name => 'typedef', :class => Rubyang::Model::Typedef },
869
+ { :name => 'uses', :class => Rubyang::Model::Uses },
870
+ { :name => 'union', :class => Rubyang::Model::Union },
871
+ { :name => 'units', :class => Rubyang::Model::Units },
872
+ { :name => 'unique', :class => Rubyang::Model::Unique },
873
+ { :name => 'value', :class => Rubyang::Model::Value },
874
+ { :name => 'when', :class => Rubyang::Model::When },
875
+ { :name => 'yang-version', :class => Rubyang::Model::YangVersion },
876
+ { :name => 'yin-element', :class => Rubyang::Model::YinElement },
877
+ ]
878
+ def self.find key
879
+ case key
880
+ when String, Symbol
881
+ @@stmt_map.find{ |h| h[:name] == key.to_s }[:class]
882
+ when Class
883
+ @@stmt_map.find{ |h| h[:class] == key }[:name]
884
+ else
885
+ @@stmt_map.find{ |h| h[:class] === key }[:name]
886
+ end
887
+ end
888
+ end
889
+ end
890
+ end
891
+
892
+ if __FILE__ == $0
893
+ model_yang_version = Rubyang::Model::YangVersion.new( '1' )
894
+ model_namespace = Rubyang::Model::Namespace.new( 'testnamespace' )
895
+ model_prefix = Rubyang::Model::Prefix.new( 'testprefix' )
896
+ model_type = Rubyang::Model::Type.new( 'string' )
897
+ model_leaf = Rubyang::Model::Leaf.new( 'testleaf', [model_type] )
898
+ model_module_substmts = [
899
+ model_yang_version,
900
+ model_namespace,
901
+ model_prefix,
902
+ model_leaf,
903
+ ]
904
+ model_module = Rubyang::Model::Module.new( 'testmodule', model_module_substmts )
905
+ p model_module
906
+ p model_module.has_substmt?( 'yang-version' )
907
+ p model_module.has_substmt?( 'namespace' )
908
+ p model_module.has_substmt?( 'prefix' )
909
+ p model_module.substmt( 'yang-version' )
910
+ p model_module.substmt( 'namespace' )
911
+ p model_module.substmt( 'prefix' )
912
+
913
+ print model_module.to_yang pretty: true
914
+ p model_module.schema_node_substmts
915
+ p model_module.not_schema_node_substmts
916
+ end
917
+