Class: Flow
- Inherits:
-
Object
- Object
- Flow
- Defined in:
- lib/args.rb
Instance Attribute Summary collapse
-
#error ⇒ Object
Returns the value of attribute error.
-
#pre_cond ⇒ Object
Returns the value of attribute pre_cond.
-
#rest ⇒ Object
Returns the value of attribute rest.
-
#usage_string ⇒ Object
Returns the value of attribute usage_string.
Instance Method Summary collapse
- #add(*cells) ⇒ Object
- #add_errline(errmsg) ⇒ Object
- #arghash ⇒ Object
- #command ⇒ Object
- #finished ⇒ Object
-
#initialize ⇒ Flow
constructor
A new instance of Flow.
- #missing_args ⇒ Object
- #parse(args, obj = nil) ⇒ Object
- #set(name, value) ⇒ Object
- #setvalue(value) ⇒ Object
- #usage ⇒ Object
Constructor Details
#initialize ⇒ Flow
Returns a new instance of Flow.
129 130 131 |
# File 'lib/args.rb', line 129 def initialize @cells = [ ] end |
Instance Attribute Details
#error ⇒ Object
Returns the value of attribute error.
127 128 129 |
# File 'lib/args.rb', line 127 def error @error end |
#pre_cond ⇒ Object
Returns the value of attribute pre_cond.
127 128 129 |
# File 'lib/args.rb', line 127 def pre_cond @pre_cond end |
#rest ⇒ Object
Returns the value of attribute rest.
127 128 129 |
# File 'lib/args.rb', line 127 def rest @rest end |
#usage_string ⇒ Object
Returns the value of attribute usage_string.
127 128 129 |
# File 'lib/args.rb', line 127 def usage_string @usage_string end |
Instance Method Details
#add(*cells) ⇒ Object
133 134 135 136 137 |
# File 'lib/args.rb', line 133 def add(*cells) cells.each { |cell| @cells << cell } end |
#add_errline(errmsg) ⇒ Object
239 240 241 242 243 244 245 246 |
# File 'lib/args.rb', line 239 def add_errline(errmsg) return if errmsg.nil? if @error.nil? @error = errmsg else @error = @error + "\n" + errmsg end end |
#arghash ⇒ Object
220 221 222 223 224 225 226 227 |
# File 'lib/args.rb', line 220 def arghash result = { } @cells.each { |cell| result[cell.name] = cell.value } result["command"] = command result end |
#command ⇒ Object
214 215 216 217 218 |
# File 'lib/args.rb', line 214 def command if @cells[-1] @cells[-1].command end end |
#finished ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/args.rb', line 159 def finished if command && @cells[-1].full? # the command was seen return true end @cells.each { |cell| if ! cell.full? return false end } return true end |
#missing_args ⇒ Object
192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/args.rb', line 192 def missing_args missing = [ ] @cells.each { |cell| if cell.missing_value missing << cell.name end } if missing.length > 0 add_errline("missing args: #{missing}") end end |
#parse(args, obj = nil) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/args.rb', line 139 def parse(args, obj = nil) @target = obj @rest = [ ] args.each_with_index { |arg, index| if finished || @error @rest = args[index..-1] break end name, value = Util.parse_line(arg) if value.nil? value = name setvalue(value) else set(name, value) end } missing = missing_args @error.nil? end |
#set(name, value) ⇒ Object
204 205 206 207 208 209 210 211 212 |
# File 'lib/args.rb', line 204 def set(name, value) @cells.each { |cell| if cell.name == name add_errline(cell.set(value, @target)) return end } add_errline("argument named #{name} not found") end |
#setvalue(value) ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/args.rb', line 172 def setvalue(value) @cells.each { |cell| if cell.full? next else error = cell.set(value, @target) if error if cell.repeatable next # repeatable cell is now full; try to set next cell else add_errline(error) return end end return end } return end |
#usage ⇒ Object
229 230 231 232 233 234 235 236 237 |
# File 'lib/args.rb', line 229 def usage names = [ ] desc = [ ] @cells.each { |cell| names << cell.name desc << cell.desc } return names, desc end |