Class: CmdCreator::SubSpecParser
- Inherits:
-
Object
- Object
- CmdCreator::SubSpecParser
- Defined in:
- lib/cmd_creator.rb
Instance Method Summary collapse
- #asub(atom) ⇒ Object
-
#initialize(sym, words, args) ⇒ SubSpecParser
constructor
A new instance of SubSpecParser.
- #parse ⇒ Object
- #replace(spec, atom, sspe) ⇒ Object
Constructor Details
#initialize(sym, words, args) ⇒ SubSpecParser
Returns a new instance of SubSpecParser.
101 102 103 |
# File 'lib/cmd_creator.rb', line 101 def initialize(sym, words, args) @sym, @words, @args = sym, words, args end |
Instance Method Details
#asub(atom) ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/cmd_creator.rb', line 148 def asub(atom) arr = atom.split(CmdCreator::Argument) tmp = [] arr.each_with_index {|ea, ind| if 1 == ind % 2 if @args[ea.to_sym] tmp << @args[ea.to_sym].to_s else return nil end else tmp << ea end } tmp.join("") end |
#parse ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/cmd_creator.rb', line 105 def parse spec = Spec.new if @sym == CmdCreator::MandatoryStop spec.type = true else spec.type = false end atom = "" while word = @words.shift case word when CmdCreator::MandatoryStart ssp = SubSpecParser.new( CmdCreator::MandatoryStop, @words, @args ).parse unless replace(spec, atom, ssp) raise CmdCreator::NotMandatoryError.new(atom) end atom = "" when CmdCreator::OptionalStart ssp = SubSpecParser.new( CmdCreator::OptionalStop, @words, @args ).parse unless replace(spec, atom, ssp) return "" end atom = "" when @sym spec << asub(atom) if atom.size > 0 spar = SpecParser.new(@words, @args).parse if spar.size > 0 spec << spec end return spec else atom << word end end return spec end |
#replace(spec, atom, sspe) ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/cmd_creator.rb', line 166 def replace(spec, atom, sspe) if atom.size > 0 subs = asub(atom) if subs spec << subs else return false end end spec << sspe if sspe.size > 0 return true end |