Class: Yerba::Scalar
- Inherits:
-
Object
show all
- Includes:
- Node
- Defined in:
- lib/yerba/scalar.rb
Instance Attribute Summary
Attributes included from Node
#key, #location, #selector
Instance Method Summary
collapse
Methods included from Node
#connected?, #document, #file_path, included, #line
Constructor Details
#initialize(value = nil, quote_style: nil) ⇒ Scalar
Returns a new instance of Scalar.
7
8
9
10
11
12
|
# File 'lib/yerba/scalar.rb', line 7
def initialize(value = nil, quote_style: nil)
init_node(nil, nil, nil, nil, nil, nil)
@value = value
@quote_style = quote_style
end
|
Instance Method Details
#==(other) ⇒ Object
51
52
53
|
# File 'lib/yerba/scalar.rb', line 51
def ==(other)
value == other
end
|
#delete ⇒ Object
63
64
65
|
# File 'lib/yerba/scalar.rb', line 63
def delete
document&.delete(@selector)
end
|
#inspect ⇒ Object
67
68
69
70
71
72
73
|
# File 'lib/yerba/scalar.rb', line 67
def inspect
if @selector
"#<Yerba::Scalar selector=#{@selector.inspect} value=#{value.inspect}>"
else
"#<Yerba::Scalar value=#{value.inspect} quote_style=#{quote_style.inspect}>"
end
end
|
#quote_style ⇒ Object
18
19
20
|
# File 'lib/yerba/scalar.rb', line 18
def quote_style
@quote_style || document&.get_quote_style(@selector)
end
|
#quote_style=(style) ⇒ Object
22
23
24
25
26
|
# File 'lib/yerba/scalar.rb', line 22
def quote_style=(style)
document&.set_quote_style(@selector, style)
@quote_style = style
end
|
#to_f ⇒ Object
47
48
49
|
# File 'lib/yerba/scalar.rb', line 47
def to_f
value.to_f
end
|
#to_i ⇒ Object
43
44
45
|
# File 'lib/yerba/scalar.rb', line 43
def to_i
value.to_i
end
|
#to_s ⇒ Object
35
36
37
|
# File 'lib/yerba/scalar.rb', line 35
def to_s
value.to_s
end
|
#to_str ⇒ Object
39
40
41
|
# File 'lib/yerba/scalar.rb', line 39
def to_str
to_s
end
|
#to_yaml ⇒ Object
55
56
57
58
59
60
61
|
# File 'lib/yerba/scalar.rb', line 55
def to_yaml
case value
when nil then "null"
when String then Formatting.quote(value, quote_style)
else value.to_s
end
end
|
#value ⇒ Object
14
15
16
|
# File 'lib/yerba/scalar.rb', line 14
def value
@value ||= document&.value_at(@selector)
end
|
#value=(new_value) ⇒ Object
Also known as:
set
28
29
30
31
32
|
# File 'lib/yerba/scalar.rb', line 28
def value=(new_value)
document&.set(@selector, new_value)
@value = new_value
end
|