Class: DotStrings::Item
- Inherits:
-
Object
- Object
- DotStrings::Item
- Defined in:
- lib/dotstrings/item.rb
Instance Attribute Summary collapse
-
#comment ⇒ Object
readonly
Returns the value of attribute comment.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(key:, value:, comment: nil) ⇒ Item
constructor
A new instance of Item.
- #to_s(escape_single_quotes: false, include_comment: true) ⇒ Object
Constructor Details
#initialize(key:, value:, comment: nil) ⇒ Item
Returns a new instance of Item.
7 8 9 10 11 |
# File 'lib/dotstrings/item.rb', line 7 def initialize(key:, value:, comment: nil) @comment = comment @key = key @value = value end |
Instance Attribute Details
#comment ⇒ Object (readonly)
Returns the value of attribute comment.
5 6 7 |
# File 'lib/dotstrings/item.rb', line 5 def comment @comment end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
5 6 7 |
# File 'lib/dotstrings/item.rb', line 5 def key @key end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
5 6 7 |
# File 'lib/dotstrings/item.rb', line 5 def value @value end |
Instance Method Details
#to_s(escape_single_quotes: false, include_comment: true) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/dotstrings/item.rb', line 13 def to_s(escape_single_quotes: false, include_comment: true) result = [] result << "/* #{comment} */" unless comment.nil? || !include_comment result << format('"%<key>s" = "%<value>s";', { key: serialize_string(key, escape_single_quotes: escape_single_quotes), value: serialize_string(value, escape_single_quotes: escape_single_quotes) }) result.join("\n") end |