Class: HTMLTag

### Home Classes Methods

### In Files

- lib/openid/yadis/htmltokenizer.rb

### Parent

HTMLToken

### Methods

- ::new
- #attr_hash
- #text

### Files

- LICENSE

### Class/Module Index

Quicksearch

- OpenID
- OpenID::AX
- OpenID::AX::AXMessage
- OpenID::AX::AttrInfo
- OpenID::AX::Error
- OpenID::AX::FetchRequest
- OpenID::AX::FetchResponse
- OpenID::AX::KeyValueMessage
- OpenID::AX::StoreRequest
- OpenID::AX::StoreResponse
- OpenID::AssertionError
- OpenID::Association
- OpenID::AssociationNegotiator
- OpenID::Consumer
- OpenID::Consumer::AssociationManager
- OpenID::Consumer::CancelResponse
- OpenID::Consumer::CheckIDRequest
- OpenID::Consumer::DiffieHellmanSHA1Session
- OpenID::Consumer::DiffieHellmanSHA256Session
- OpenID::Consumer::DiffieHellmanSession
- OpenID::Consumer::DiscoveredServices
- OpenID::Consumer::DiscoveryManager
- OpenID::Consumer::FailureResponse
- OpenID::Consumer::IdResHandler
- OpenID::Consumer::NoEncryptionSession
- OpenID::Consumer::Response
- OpenID::Consumer::Session
- OpenID::Consumer::SetupNeededResponse
- OpenID::Consumer::SuccessResponse
- OpenID::CryptUtil
- OpenID::DiffieHellman
- OpenID::DiscoveryFailure
- OpenID::Extension
- OpenID::FetchingError
- OpenID::HTTPRedirectLimitReached
- OpenID::HTTPResponse
- OpenID::HTTPStatusError
- OpenID::InvalidOpenIDNamespace
- OpenID::KVFormError
- OpenID::KVPostNetworkError
- OpenID::Message
- OpenID::Message::KeyNotFound
- OpenID::NamespaceAliasRegistrationError
- OpenID::NamespaceMap
- OpenID::Nonce
- OpenID::OAuth
- OpenID::OAuth::Request
- OpenID::OAuth::Response
- OpenID::OpenIDError
- OpenID::OpenIDServiceEndpoint
- OpenID::PAPE
- OpenID::PAPE::Request
- OpenID::PAPE::Response
- OpenID::ProtocolError
- OpenID::RealmVerificationRedirected
- OpenID::SReg
- OpenID::SReg::NamespaceError
- OpenID::SReg::Request
- OpenID::SReg::Response
- OpenID::SSLFetchingError
- OpenID::Server
- OpenID::Server::AlreadySigned
- OpenID::Server::AssociateRequest
- OpenID::Server::BaseServerSession
- OpenID::Server::CheckAuthRequest
- OpenID::Server::CheckIDRequest
- OpenID::Server::Decoder
- OpenID::Server::DiffieHellmanSHA1ServerSession
- OpenID::Server::DiffieHellmanSHA256ServerSession
- OpenID::Server::Encoder
- OpenID::Server::EncodingError
- OpenID::Server::MalformedReturnURL
- OpenID::Server::MalformedTrustRoot
- OpenID::Server::NoReturnToError
- OpenID::Server::OpenIDRequest
- OpenID::Server::OpenIDResponse
- OpenID::Server::PlainTextServerSession
- OpenID::Server::ProtocolError
- OpenID::Server::Server
- OpenID::Server::Signatory
- OpenID::Server::SigningEncoder
- OpenID::Server::UntrustedReturnURL
- OpenID::Server::VersionError
- OpenID::Server::WebResponse
- OpenID::ServerError
- OpenID::StandardFetcher
- OpenID::Store
- OpenID::Store::Filesystem
- OpenID::Store::Interface
- OpenID::Store::Memcache
- OpenID::Store::Memory
- OpenID::TrustRoot
- OpenID::TrustRoot::TrustRoot
- OpenID::TypeURIMismatch
- OpenID::UI
- OpenID::UI::Request
- OpenID::URINorm
- OpenID::UndefinedOpenIDNamespace
- OpenID::Util
- OpenID::Yadis
- OpenID::Yadis::BasicServiceEndpoint
- OpenID::Yadis::CompoundFilter
- OpenID::Yadis::DiscoveryResult
- OpenID::Yadis::TransformFilterMaker
- OpenID::Yadis::XRDSError
- OpenID::Yadis::XRDSFraud
- OpenID::Yadis::XRI
- OpenID::Yadis::XRI::ProxyResolver
- OpenID::Yadis::XRI::XRIHTTPError
- HMAC
- HMAC::Base
- HMAC::SHA1
- HMAC::SHA256
- HMAC::SHA384
- HMAC::SHA512
- Net
- Net::HTTP
- HTMLComment
- HTMLTag
- HTMLText
- HTMLToken
- HTMLTokenizer
- HTMLTokenizerError
- Object

No matching classes.

# HTMLTag

Class representing an HTML tag

### Attributes

end_tag[R]
tag_name[R]

### Public Class Methods

new(text) click to toggle source

    # File lib/openid/yadis/htmltokenizer.rb, line 225
    def initialize(text)
      super(text)
      if << != text[0] or >> != text[-1]
        raise HTMLTokenizerError, "Text passed to HTMLComment.initialize is not a comment"
      end

      @attr_hash = Hash.new
      @raw = text

      tag_name = text.scan(/[\w:-]+/)[0]
      if tag_name.nil?
        raise HTMLTokenizerError, "Error, tag is nil: #{tag_name}"
      end

      if // == text[1]
        # It's an end tag
        @end_tag = true
        @tag_name = '/' + tag_name.downcase
      else
        @end_tag = false
        @tag_name = tag_name.downcase
      end

      @hashed = false
    end

### Public Instance Methods

attr_hash() click to toggle source

Retrieve a hash of all the tag's attributes. Lazily done, so that if you don't look at a tag's attributes things go quicker

    # File lib/openid/yadis/htmltokenizer.rb, line 254
    def attr_hash
      # Lazy initialize == don't build the hash until it's needed
      if !@hashed
        if !@end_tag
          # Get the attributes
          attr_arr = @raw.scan(/<[\w:-]+\s+(.*?)\/?>/)[0]
          if attr_arr.kind_of?(Array)
            # Attributes found, parse them
            attrs = attr_arr[0]
            attr_arr = attrs.scan(/\s*([\w:-]+)(?:\s*=\s*("[^"]*"|'[^']*'|([^"'>][^\s>]*)))?/)
            # clean up the array by:
            # * setting all nil elements to true
            # * removing enclosing quotes
            attr_arr.each {
              |item|
              val = if item[1].nil?
                      item[0]
                    elsif '"'[0] == item[1][0] or '\'[0] == item[1][0]
                      item[1][1 .. -2]
                    else
                      item[1]
                    end
              @attr_hash[item[0].downcase] = val
            }
          end
        end
        @hashed = true
      end

      #p self

      @attr_hash
    end

text() click to toggle source

Get the 'alt' text for a tag, if it exists, or an empty string otherwise

    # File lib/openid/yadis/htmltokenizer.rb, line 289
    def text
      if !end_tag
        case tag_name
        when 'img'
          if !attr_hash['alt'].nil?
            return attr_hash['alt']
          end
        when 'applet'
          if !attr_hash['alt'].nil?
            return attr_hash['alt']
          end
        end
      end
      return ''
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.