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.
574 575 576 577 578 579 580 581 582 |
# File 'lib/web/testing.rb', line 574 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:
572 573 574 |
# File 'lib/web/testing.rb', line 572 def fields @fields end |
#unmodified_fields ⇒ Object (readonly)
:nodoc:
572 573 574 |
# File 'lib/web/testing.rb', line 572 def unmodified_fields @unmodified_fields end |
Class Method Details
.flatten(node, newhash = {}, nameroot = "") ⇒ Object
:nodoc:
639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 |
# File 'lib/web/testing.rb', line 639 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
611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 |
# File 'lib/web/testing.rb', line 611 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::Connection::MULTIPLE_KEY.match(key) retval[key] ||= [] retval[key] = (retval[key] + ).uniq else retval[key] = .join(",") end else if m = Web::Connection::MULTIPLE_KEY.match(key) retval[key] ||= [] retval[key] << value else retval[key] = value end end end retval end |
#push_field(name, value) ⇒ Object
605 606 607 608 609 |
# File 'lib/web/testing.rb', line 605 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
588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 |
# File 'lib/web/testing.rb', line 588 def push_impl hash, name, value if name =~ Web::Connection::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
584 585 586 |
# File 'lib/web/testing.rb', line 584 def valid_key? (aKey) unmodified_fields.has_key?(aKey) || fields.has_key?(aKey) end |