Class: Yaml::Sort::Scalar

Inherits:
Value
  • Object
show all
Defined in:
lib/yaml/sort/scalar.rb

Direct Known Subclasses

Item

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Value

#comments, #sort

Constructor Details

#initialize(value) ⇒ Scalar

Returns a new instance of Scalar.



8
9
10
11
12
13
# File 'lib/yaml/sort/scalar.rb', line 8

def initialize(value)
  super()
  @comment = value[:comment] || []
  @value = value[:value]
  @indent = value[:indent] || ""
end

Instance Attribute Details

#indentObject (readonly)

Returns the value of attribute indent.



6
7
8
# File 'lib/yaml/sort/scalar.rb', line 6

def indent
  @indent
end

#valueObject (readonly)

Returns the value of attribute value.



6
7
8
# File 'lib/yaml/sort/scalar.rb', line 6

def value
  @value
end

Instance Method Details

#<=>(other) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/yaml/sort/scalar.rb', line 15

def <=>(other)
  if other.is_a?(Scalar)
    value <=> other.value
  else
    0
  end
end

#to_s(skip_first_indent: false) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/yaml/sort/scalar.rb', line 23

def to_s(skip_first_indent: false)
  if skip_first_indent
    super + value
  else
    super + indent + value
  end
end