Class: Rubyang::Model::BaseStmt
- Inherits:
-
Object
- Object
- Rubyang::Model::BaseStmt
- Defined in:
- lib/rubyang/model.rb
Instance Method Summary collapse
- #has_substmt?(substmt) ⇒ Boolean
-
#initialize(substmts = []) ⇒ BaseStmt
constructor
A new instance of BaseStmt.
- #not_schema_node_substmts ⇒ Object
- #schema_node_substmts ⇒ Object
- #substatements ⇒ Object
- #substmt(substmt, strict: false) ⇒ Object
- #substmts(substmts, strict: false) ⇒ Object
- #to_s(parent = true) ⇒ Object
- #to_yang(level = 0, pretty: false, indent: 2) ⇒ Object
- #without_not_schema_node_substmts ⇒ Object
Constructor Details
#initialize(substmts = []) ⇒ BaseStmt
Returns a new instance of BaseStmt.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/rubyang/model.rb', line 58 def initialize substmts=[] # raise if received susstatements has invalid substatement substmts.each{ |s| unless self.substatements.include? StmtMap.find( s.class ).intern raise ArgumentError, "#{StmtMap.find( s.class )} is not #{self.class}'s substatement" end } # raise if received susstatements does not satisfy defined substatements' cardinality self.substatements.each{ |k, v| unless v.include? substmts.count{ |s| StmtMap.find( s ).intern == k } raise ArgumentError, "substatement #{StmtMap.find( k )} is not in #{self.class} #{k}'s cardinality" end } # raise if received susstatements has invalid substatement class substmts.each{ |s| unless BaseStmt === s raise ArgumentError, "#{s.class} is not Rubyang::Model's class" end } @substmts = substmts end |
Instance Method Details
#has_substmt?(substmt) ⇒ Boolean
106 107 108 109 110 111 112 113 114 115 |
# File 'lib/rubyang/model.rb', line 106 def has_substmt? substmt unless self.substatements[substmt.intern] raise ArgumentError, "#{StmtMap.find( substmt ).class} is not #{self.class}'s substatement" end if @substmts.find{ |s| StmtMap.find( substmt ) === s } true else false end end |
#not_schema_node_substmts ⇒ Object
119 120 121 |
# File 'lib/rubyang/model.rb', line 119 def not_schema_node_substmts @substmts.select{ |s| not SchemaNodeList.include? StmtMap.find( s ) } end |
#schema_node_substmts ⇒ Object
116 117 118 |
# File 'lib/rubyang/model.rb', line 116 def schema_node_substmts @substmts.select{ |s| SchemaNodeList.include? StmtMap.find( s ) } end |
#substatements ⇒ Object
55 56 57 |
# File 'lib/rubyang/model.rb', line 55 def substatements {} end |
#substmt(substmt, strict: false) ⇒ Object
86 87 88 89 90 91 92 93 94 |
# File 'lib/rubyang/model.rb', line 86 def substmt substmt, strict: false raise TypeError unless String === substmt if strict unless self.substatements[substmt.intern] raise ArgumentError, "#{StmtMap.find( s ).class} is not #{self.class}'s substatement" end end @substmts.select{ |_s| StmtMap.find( substmt ) === _s } end |
#substmts(substmts, strict: false) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/rubyang/model.rb', line 95 def substmts substmts, strict: false raise TypeError unless Array === substmts if strict substmts.each{ |s| unless self.substatements[s.intern] raise ArgumentError, "#{StmtMap.find( s ).class} is not #{self.class}'s substatement" end } end @substmts.select{ |_s| substmts.find{ |s| StmtMap.find( s ) === _s } } end |
#to_s(parent = true) ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/rubyang/model.rb', line 79 def to_s parent=true head, vars, tail = "#<#{self.class.to_s}:0x#{(self.object_id << 1).to_s(16).rjust(14,'0')} ", Array.new, ">" if parent vars.push "@substmts=#{@substmts.map{|s| s.to_s(false)}}" end head + vars.join(', ') + tail end |
#to_yang(level = 0, pretty: false, indent: 2) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/rubyang/model.rb', line 125 def to_yang level=0, pretty: false, indent: 2 str = "" str += " " * indent * level if pretty str += "#{StmtMap.find( self )} #{self.arg}" if @substmts.size > 0 str += " {\n" @substmts.each{ |s| str += s.to_yang level+1, pretty: pretty, indent: indent } str += " " * indent * level if pretty str += "}\n" else str += ";\n" end end |
#without_not_schema_node_substmts ⇒ Object
122 123 124 |
# File 'lib/rubyang/model.rb', line 122 def without_not_schema_node_substmts self.class.new( self.arg, self.not_schema_node_substmts ) end |