HttpWatch Automation Reference - Version 11.x
Using HttpWatch Automation with Ruby / Ruby - Accessing Data in a Log File / Ruby - Using Collection Classes
In This Topic
    Ruby - Using Collection Classes
    In This Topic

    Classes Containing A Variable Length Lists Of Objects

    In many cases, the information collected by HttpWatch consists of collections of items (Pages, Entries, etc.) In these cases, the automation library provides a collection class for each type of item. These collection classes and the types they contain are as follows:

    Accessing the Contents of a Collection Class

    All the collection classes listed above have the following two properties:

    • The Count property, which returns the number of objects in the collection
    • The Item property, which access an individual member of the collection

    In Ruby, the implementation of the Item property allows individual members of the collection to be accessed in two ways:

    • The item property can be used as a default method to access any member of the collection by index
    • The Ruby each method can be used to iterate through the collection

     

    For example, the following code fragment steps through the Log object's Entries collection and prints out the URL for each Entry:

     

    Using each method with Collection Classes
    Copy Code
    # Loop through each Entry object in the Entries collection
    
    log.Entries.each do |entry|
        # Prints the URL of each entry recorded
        puts entry.URL
    endf
    

     

    And the following example uses the default method notation to retrieve the first Entry in the Log object's Entries collection:

     

    Accessing Collection Members by Index
    Copy Code
    # Prints the URL of the first entry recorded
    puts log.Entries(0).URL 
    

     

    Some classes such as Timings and PageEvents do not hold a variable length list of objects. Instead these classes contain a fixed set of named objects. For example, the Timings class has nine properties that return Timing objects representing timings such as the DNS Lookup and Connect timings.

     

    See Also