Class: SassC::Script::Value
- Inherits:
-
Object
- Object
- SassC::Script::Value
- Defined in:
- lib/sassc/script/value.rb
Overview
The abstract superclass for SassScript objects. Many of these methods, especially the ones that correspond to SassScript operations, are designed to be overridden by subclasses which may change the semantics somewhat. The operations listed here are just the defaults.
Defined Under Namespace
Classes: Bool, Color, List, Map, Number, String
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the options hash for this node.
-
#source_range ⇒ Object
The source range in the document on which this node appeared.
-
#value ⇒ Object
readonly
Returns the pure Ruby value of the value.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Compares this object to ‘other`.
- #assert_int! ⇒ Object
-
#bracketed ⇒ Object
Whether the value is surrounded by square brackets.
-
#eql?(other) ⇒ Boolean
True if this Value is the same as ‘other`.
-
#hash ⇒ Object
Returns the hash code of this value.
-
#initialize(value = nil) ⇒ Value
constructor
Creates a new value.
-
#inspect ⇒ Object
Returns a system inspect value for this object.
-
#null? ⇒ Boolean
Returns ‘false` (all Values are truthy).
-
#separator ⇒ Object
Returns the separator for this value.
-
#to_a ⇒ Object
Returns the value of this Value as an array.
-
#to_bool ⇒ Object
Returns ‘true` (all Values are truthy).
-
#to_h ⇒ Hash<Value, Value>
Returns the value of this value as a hash.
-
#to_i ⇒ Object
Returns the integer value of this value.
-
#to_s(opts = {}) ⇒ String
(also: #to_sass)
Returns the string representation of this value as it would be output to the CSS document.
-
#with_contents(contents, separator: self.separator, bracketed: self.bracketed) ⇒ Sass::Script::Value::List
Creates a new list containing ‘contents` but with the same brackets and separators as this object, when interpreted as a list.
Constructor Details
#initialize(value = nil) ⇒ Value
Creates a new value.
18 19 20 21 22 |
# File 'lib/sassc/script/value.rb', line 18 def initialize(value = nil) value.freeze unless value.nil? || value == true || value == false @value = value @options = nil end |
Instance Attribute Details
#options ⇒ Object
Returns the options hash for this node. Raises SassC::SyntaxError if the value was created outside of the parser and #to_s was called on it
32 33 34 35 |
# File 'lib/sassc/script/value.rb', line 32 def return @options if @options raise SassC::SyntaxError.new("The #options attribute is not set on this #{self.class}. This error is probably occurring because #to_s was called on this value within a custom Sass function without first setting the #options attribute.") end |
#source_range ⇒ Object
The source range in the document on which this node appeared.
15 16 17 |
# File 'lib/sassc/script/value.rb', line 15 def source_range @source_range end |
#value ⇒ Object (readonly)
Returns the pure Ruby value of the value. The type of this value varies based on the subclass.
12 13 14 |
# File 'lib/sassc/script/value.rb', line 12 def value @value end |
Instance Method Details
#==(other) ⇒ Object
Compares this object to ‘other`
59 60 61 |
# File 'lib/sassc/script/value.rb', line 59 def ==(other) self.class == other.class && value == other.value end |
#assert_int! ⇒ Object
70 |
# File 'lib/sassc/script/value.rb', line 70 def assert_int!; to_i; end |
#bracketed ⇒ Object
Whether the value is surrounded by square brackets. For non-list values, this will be ‘false`.
80 81 82 |
# File 'lib/sassc/script/value.rb', line 80 def bracketed false end |
#eql?(other) ⇒ Boolean
True if this Value is the same as ‘other`
44 45 46 |
# File 'lib/sassc/script/value.rb', line 44 def eql?(other) self == other end |
#hash ⇒ Object
Returns the hash code of this value. Two objects’ hash codes should be equal if the objects are equal.
39 40 41 |
# File 'lib/sassc/script/value.rb', line 39 def hash value.hash end |
#inspect ⇒ Object
Returns a system inspect value for this object
49 50 51 |
# File 'lib/sassc/script/value.rb', line 49 def inspect value.inspect end |
#null? ⇒ Boolean
Returns ‘false` (all Values are truthy)
112 113 114 |
# File 'lib/sassc/script/value.rb', line 112 def null? false end |
#separator ⇒ Object
Returns the separator for this value. For non-list-like values or the empty list, this will be ‘nil`. For lists or maps, it will be `:space` or `:comma`.
74 75 76 |
# File 'lib/sassc/script/value.rb', line 74 def separator nil end |
#to_a ⇒ Object
Returns the value of this Value as an array. Single Values are considered the same as single-element arrays.
86 87 88 |
# File 'lib/sassc/script/value.rb', line 86 def to_a [self] end |
#to_bool ⇒ Object
Returns ‘true` (all Values are truthy)
54 55 56 |
# File 'lib/sassc/script/value.rb', line 54 def to_bool true end |
#to_h ⇒ Hash<Value, Value>
Returns the value of this value as a hash. Most values don’t have hash representations, but [Map]s and empty [List]s do.
95 96 97 |
# File 'lib/sassc/script/value.rb', line 95 def to_h raise SassC::SyntaxError.new("#{inspect} is not a map.") end |
#to_i ⇒ Object
Returns the integer value of this value. Raises SassC::SyntaxError if this value doesn’t implment integer conversion.
65 66 67 |
# File 'lib/sassc/script/value.rb', line 65 def to_i raise SassC::SyntaxError.new("#{inspect} is not an integer.") end |
#to_s(opts = {}) ⇒ String Also known as: to_sass
Returns the string representation of this value as it would be output to the CSS document.
106 107 108 |
# File 'lib/sassc/script/value.rb', line 106 def to_s(opts = {}) SassC::Util.abstract(self) end |
#with_contents(contents, separator: self.separator, bracketed: self.bracketed) ⇒ Sass::Script::Value::List
Creates a new list containing ‘contents` but with the same brackets and separators as this object, when interpreted as a list.
123 124 125 |
# File 'lib/sassc/script/value.rb', line 123 def with_contents(contents, separator: self.separator, bracketed: self.bracketed) SassC::Script::Value::List.new(contents, separator: separator, bracketed: bracketed) end |