Class: Dotini::KeyValuePair
- Inherits:
-
Object
- Object
- Dotini::KeyValuePair
- Defined in:
- lib/dotini/key_value_pair.rb
Overview
Key/value pair, with optional prepended and inline comments
Instance Attribute Summary collapse
-
#inline_comment ⇒ Object
Returns the value of attribute inline_comment.
-
#key ⇒ Object
Returns the value of attribute key.
-
#prepended_comments ⇒ Object
Returns the value of attribute prepended_comments.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize ⇒ KeyValuePair
constructor
Creates a new, undefined key/value pair with no comments.
-
#to_s ⇒ Object
Represents the key/value pair as a string.
Constructor Details
#initialize ⇒ KeyValuePair
Creates a new, undefined key/value pair with no comments
9 10 11 12 13 14 |
# File 'lib/dotini/key_value_pair.rb', line 9 def initialize @key = nil @value = nil @prepended_comments = [] @inline_comment = nil end |
Instance Attribute Details
#inline_comment ⇒ Object
Returns the value of attribute inline_comment.
6 7 8 |
# File 'lib/dotini/key_value_pair.rb', line 6 def inline_comment @inline_comment end |
#key ⇒ Object
Returns the value of attribute key.
6 7 8 |
# File 'lib/dotini/key_value_pair.rb', line 6 def key @key end |
#prepended_comments ⇒ Object
Returns the value of attribute prepended_comments.
6 7 8 |
# File 'lib/dotini/key_value_pair.rb', line 6 def prepended_comments @prepended_comments end |
#value ⇒ Object
Returns the value of attribute value.
6 7 8 |
# File 'lib/dotini/key_value_pair.rb', line 6 def value @value end |
Instance Method Details
#to_s ⇒ Object
Represents the key/value pair as a string
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/dotini/key_value_pair.rb', line 17 def to_s buffer = StringIO.new prepended_comments.each do |line| buffer << line << "\n" end unless key.nil? buffer << "#{key} = #{value}" buffer << if inline_comment.nil? "\n" else " #{inline_comment}\n" end end buffer.string end |