Class: Rubyang::Model::ArgStmt

Inherits:
BaseStmt
  • Object
show all
Defined in:
lib/rubyang/model.rb

Instance Method Summary collapse

Methods inherited from BaseStmt

#has_substmt?, #not_schema_node_substmts, #schema_node_substmts, #substatements, #substmt, #substmts, #to_yang, #without_not_schema_node_substmts

Constructor Details

#initialize(arg, substmts = []) ⇒ ArgStmt

Returns a new instance of ArgStmt.



146
147
148
149
150
151
152
# File 'lib/rubyang/model.rb', line 146

def initialize arg, substmts=[]
  super substmts
  @arg = arg
  unless valid_arg? arg
    raise ArgumentError, "Invalid Argument: '#{arg}'"
  end
end

Instance Method Details

#argObject



161
162
163
# File 'lib/rubyang/model.rb', line 161

def arg
  @arg
end

#arg_regexpObject



164
165
166
# File 'lib/rubyang/model.rb', line 164

def arg_regexp
  '(?:.*)'
end

#to_s(parent = true) ⇒ Object



153
154
155
156
157
158
159
160
# File 'lib/rubyang/model.rb', line 153

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 "@arg=#{@arg.to_s}"
    vars.push "@substmts=#{@substmts.map{|s| s.to_s(false)}}"
  end
  head + vars.join(', ') + tail
end

#valid_arg?(arg) ⇒ Boolean

Returns:

  • (Boolean)


167
168
169
170
# File 'lib/rubyang/model.rb', line 167

def valid_arg? arg
  re = Regexp.new( "^#{arg_regexp}$" )
  re === arg
end