Class: Sass::Selector::Simple

### Home Classes Methods

### In Files

- lib/sass/selector/simple.rb

### Parent

Object

### Methods

- #==
- #eql?
- #hash
- #inspect
- #to_a
- #to_s
- #unify
- #unify_namespaces

### Class/Module Index

Quicksearch

- Sass
- Sass::CSS
- Sass::CacheStores
- Sass::CacheStores::Base
- Sass::CacheStores::Chain
- Sass::CacheStores::Filesystem
- Sass::CacheStores::Memory
- Sass::CacheStores::Null
- Sass::Callbacks
- Sass::Callbacks::InstanceMethods
- Sass::Engine
- Sass::Engine::Line
- Sass::Environment
- Sass::Exec
- Sass::Exec::Generic
- Sass::Exec::Sass
- Sass::Exec::SassConvert
- Sass::Exec::Scss
- Sass::Importers
- Sass::Importers::Base
- Sass::Importers::Filesystem
- Sass::Logger
- Sass::Logger::Base
- Sass::Logger::LogLevel
- Sass::Logger::LogLevel::ClassMethods
- Sass::Media
- Sass::Media::Query
- Sass::Media::QueryList
- Sass::Plugin
- Sass::Plugin::Compiler
- Sass::Plugin::Configuration
- Sass::Plugin::MerbBootLoader
- Sass::Plugin::Rack
- Sass::Plugin::StalenessChecker
- Sass::Repl
- Sass::SCSS
- Sass::SCSS::CssParser
- Sass::SCSS::Parser
- Sass::SCSS::RX
- Sass::SCSS::ScriptLexer
- Sass::SCSS::ScriptParser
- Sass::SCSS::StaticParser
- Sass::Script
- Sass::Script::ArgList
- Sass::Script::Bool
- Sass::Script::Color
- Sass::Script::CssLexer
- Sass::Script::CssParser
- Sass::Script::Funcall
- Sass::Script::Functions
- Sass::Script::Functions::EvaluationContext
- Sass::Script::Interpolation
- Sass::Script::Lexer
- Sass::Script::List
- Sass::Script::Literal
- Sass::Script::Node
- Sass::Script::Null
- Sass::Script::Number
- Sass::Script::Operation
- Sass::Script::Parser
- Sass::Script::String
- Sass::Script::StringInterpolation
- Sass::Script::UnaryOperation
- Sass::Script::Variable
- Sass::Selector
- Sass::Selector::AbstractSequence
- Sass::Selector::Attribute
- Sass::Selector::Class
- Sass::Selector::CommaSequence
- Sass::Selector::Element
- Sass::Selector::Id
- Sass::Selector::Interpolation
- Sass::Selector::Parent
- Sass::Selector::Placeholder
- Sass::Selector::Pseudo
- Sass::Selector::SelectorPseudoClass
- Sass::Selector::Sequence
- Sass::Selector::Simple
- Sass::Selector::SimpleSequence
- Sass::Selector::Universal
- Sass::Shared
- Sass::Supports
- Sass::Supports::Condition
- Sass::Supports::Declaration
- Sass::Supports::Interpolation
- Sass::Supports::Negation
- Sass::Supports::Operator
- Sass::SyntaxError
- Sass::Tree
- Sass::Tree::CharsetNode
- Sass::Tree::CommentNode
- Sass::Tree::ContentNode
- Sass::Tree::CssImportNode
- Sass::Tree::DebugNode
- Sass::Tree::DirectiveNode
- Sass::Tree::EachNode
- Sass::Tree::ExtendNode
- Sass::Tree::ForNode
- Sass::Tree::FunctionNode
- Sass::Tree::IfNode
- Sass::Tree::ImportNode
- Sass::Tree::MediaNode
- Sass::Tree::MixinDefNode
- Sass::Tree::MixinNode
- Sass::Tree::Node
- Sass::Tree::PropNode
- Sass::Tree::ReturnNode
- Sass::Tree::RootNode
- Sass::Tree::RuleNode
- Sass::Tree::SupportsNode
- Sass::Tree::TraceNode
- Sass::Tree::VariableNode
- Sass::Tree::Visitors
- Sass::Tree::Visitors::Base
- Sass::Tree::Visitors::CheckNesting
- Sass::Tree::Visitors::Convert
- Sass::Tree::Visitors::Cssize
- Sass::Tree::Visitors::DeepCopy
- Sass::Tree::Visitors::Extend
- Sass::Tree::Visitors::Perform
- Sass::Tree::Visitors::SetOptions
- Sass::Tree::Visitors::ToCss
- Sass::Tree::WarnNode
- Sass::Tree::WhileNode
- Sass::UnitConversionError
- Sass::Util
- Sass::Util::MultibyteStringScanner
- Sass::Util::StaticConditionalContext
- Sass::Util::SubsetMap
- Sass::Util::Test
- Sass::Version
- ActionController
- ActionController::Base
- Object

No matching classes.

# Sass::Selector::Simple

The abstract superclass for simple selectors (that is, those that don't compose multiple selectors).

### Attributes

filename[RW]

The name of the file in which this selector was declared, or `nil` if it was not declared in a file (e.g. on stdin).

@return [String, nil]

line[RW]

The line of the Sass template on which this selector was declared.

@return [Fixnum]

### Public Instance Methods

==(other) click to toggle source
Alias for: eql?
eql?(other) click to toggle source

Checks equality between this and another object.

By default, this is based on the value of {#to_a}, so if that contains information irrelevant to the identity of the selector, this should be overridden.

@param other [Object] The object to test equality against @return [Boolean] Whether or not this is equal to `other`

    # File lib/sass/selector/simple.rb, line 61
    def eql?(other)
      other.class == self.class && other.hash == self.hash && other.to_a.eql?(to_a)
    end

Also aliased as: ==
hash() click to toggle source

Returns a hash code for this selector object.

By default, this is based on the value of {#to_a}, so if that contains information irrelevant to the identity of the selector, this should be overridden.

@return [Fixnum]

    # File lib/sass/selector/simple.rb, line 49
    def hash
      @_hash ||= to_a.hash
    end

inspect() click to toggle source

Returns a string representation of the node. This is basically the selector string.

@return [String]

    # File lib/sass/selector/simple.rb, line 32
    def inspect
      to_a.map {|e| e.is_a?(Sass::Script::Node) ? "\#{#{e.to_sass}}" : e}.join
    end

to_a() click to toggle source

Returns a representation of the node as an array of strings and potentially {Sass::Script::Node}s (if there's interpolation in the selector). When the interpolation is resolved and the strings are joined together, this will be the string representation of this node.

@return [Array<String, Sass::Script::Node>]

    # File lib/sass/selector/simple.rb, line 24
    def to_a
      Sass::Util.abstract(self)
    end

to_s() click to toggle source

@see {#inspect} @return [String]

    # File lib/sass/selector/simple.rb, line 38
    def to_s
      inspect
    end

unify(sels) click to toggle source

Unifies this selector with a {SimpleSequence}'s {SimpleSequence#members members array}, returning another `SimpleSequence` members array that matches both this selector and the input selector.

By default, this just appends this selector to the end of the array (or returns the original array if this selector already exists in it).

@param sels [Array<Simple>] A {SimpleSequence}'s {SimpleSequence#members members array} @return [Array<Simple>, nil] A {SimpleSequence} {SimpleSequence#members members array}

    matching both `sels` and this selector,
    or `nil` if this is impossible (e.g. unifying `#foo` and `#bar`)

@raise [Sass::SyntaxError] If this selector cannot be unified.

    This will only ever occur when a dynamic selector,
    such as {Parent} or {Interpolation}, is used in unification.
    Since these selectors should be resolved
    by the time extension and unification happen,
    this exception will only ever be raised as a result of programmer error

    # File lib/sass/selector/simple.rb, line 83
    def unify(sels)
      return sels if sels.any? {|sel2| eql?(sel2)}
      sels_with_ix = Sass::Util.enum_with_index(sels)
      _, i =
        if self.is_a?(Pseudo) || self.is_a?(SelectorPseudoClass)
          sels_with_ix.find {|sel, _| sel.is_a?(Pseudo) && (sels.last.final? || sels.last.type == :element)}
        else
          sels_with_ix.find {|sel, _| sel.is_a?(Pseudo) || sel.is_a?(SelectorPseudoClass)}
        end
      return sels + [self] unless i
      return sels[0...i] + [self] + sels[i..-1]
    end

### Protected Instance Methods

unify_namespaces(ns1, ns2) click to toggle source

Unifies two namespaces, returning a namespace that works for both of them if possible.

@param ns1 [String, nil] The first namespace.

    `nil` means none specified, e.g. `foo`.
    The empty string means no namespace specified, e.g. `|foo`.
    `"*"` means any namespace is allowed, e.g. `*|foo`.

@param ns2 [String, nil] The second namespace. See `ns1`. @return [Array(String or nil, Boolean)]

    The first value is the unified namespace, or `nil` for no namespace.
    The second value is whether or not a namespace that works for both inputs
    could be found at all.
    If the second value is `false`, the first should be ignored.

    # File lib/sass/selector/simple.rb, line 111
    def unify_namespaces(ns1, ns2)
      return nil, false unless ns1 == ns2 || ns1.nil? || ns1 == ['*'] || ns2.nil? || ns2 == ['*']
      return ns2, true if ns1 == ['*']
      return ns1, true if ns2 == ['*']
      return ns1 || ns2, true
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.