Class: Web::Testing::MultiHashTree
Overview
could I get an explanation of this? just for me? please? not to long… probably not longer than this comment here.
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
:nodoc:.
-
#unmodified_fields ⇒ Object
readonly
:nodoc:.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(fields = {}) ⇒ MultiHashTree
constructor
A new instance of MultiHashTree.
- #params(values) ⇒ Object
- #push_field(name, value) ⇒ Object
- #push_impl(hash, name, value) ⇒ Object
- #valid_key?(aKey) ⇒ Boolean
Constructor Details
#initialize(fields = {}) ⇒ MultiHashTree
Returns a new instance of MultiHashTree.
454 455 456 457 458 459 460 461 462 |
# File 'lib/web/testing.rb', line 454 def initialize fields = {} @fields = {} @unmodified_fields = {} fields.each do |k,value_array| value_array.each{ |v| push_field k, v } end end |
Instance Attribute Details
#fields ⇒ Object (readonly)
:nodoc:
452 453 454 |
# File 'lib/web/testing.rb', line 452 def fields @fields end |
#unmodified_fields ⇒ Object (readonly)
:nodoc:
452 453 454 |
# File 'lib/web/testing.rb', line 452 def unmodified_fields @unmodified_fields end |
Class Method Details
.flatten(node, newhash = {}, nameroot = "") ⇒ Object
:nodoc:
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 |
# File 'lib/web/testing.rb', line 519 def MultiHashTree.flatten node, newhash = {} , nameroot = "" # :nodoc: if node.kind_of? Hash node.each do |k,v| if nameroot == "" varname = k else varname = "#{nameroot}.#{k}" end flatten( v, newhash, varname ) end elsif node.kind_of? Array unless node.find { |i| !i.kind_of? String } newhash[nameroot] = node else node.each_with_index do |v,i| flatten( v, newhash, "#{nameroot}[#{i}]" ) end end else newhash[ nameroot ]=node end newhash end |
Instance Method Details
#params(values) ⇒ Object
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 |
# File 'lib/web/testing.rb', line 491 def params values retval = @unmodified_fields.clone values.each do |key,value| if value.kind_of? SelectHash = [] value.each{ |k,v| .push k if v } if m = Web::CGI::MULTIPLE_KEY.match(key) retval[key] ||= [] retval[key] = (retval[key] + ).uniq else retval[key] = .join(",") end else if m = Web::CGI::MULTIPLE_KEY.match(key) retval[key] ||= [] retval[key] << value else retval[key] = value end end end retval end |
#push_field(name, value) ⇒ Object
485 486 487 488 489 |
# File 'lib/web/testing.rb', line 485 def push_field name, value @unmodified_fields[name] ||= [] @unmodified_fields[name].push value push_impl @fields, name, value end |
#push_impl(hash, name, value) ⇒ Object
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 |
# File 'lib/web/testing.rb', line 468 def push_impl hash, name, value if name =~ Web::CGI::MULTIPLE_KEY && !value.kind_of?(Web::Testing::SelectHash) hash[name] ||= [] hash[name].push value elsif m = /^(\w+(\[\])?)\.(.+)/.match(name) hash[m[1]] ||= {} push_impl(hash[m[1]], m[3], value) elsif m = /^(\w+)\[(\d+)\].(.+)/.match(name) hash[m[1]] ||= [] hash[m[1]][m[2].to_i] ||= {} push_impl hash[m[1]][m[2].to_i], m[3], value else hash[name] ||= [] hash[name].push(value) end end |
#valid_key?(aKey) ⇒ Boolean
464 465 466 |
# File 'lib/web/testing.rb', line 464 def valid_key? (aKey) unmodified_fields.has_key?(aKey) || fields.has_key?(aKey) end |