Class: DotStrings::Item
- Inherits:
-
Object
- Object
- DotStrings::Item
- Defined in:
- lib/dotstrings/item.rb
Overview
Represents a localized string item.
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
- #==(other) ⇒ Object
- #eql?(other) ⇒ Boolean
-
#initialize(key:, value:, comment: nil) ⇒ Item
constructor
A new instance of Item.
-
#to_s(escape_single_quotes: false, include_comment: true) ⇒ Object
Serializes the item to string.
Constructor Details
#initialize(key:, value:, comment: nil) ⇒ Item
Returns a new instance of Item.
9 10 11 12 13 |
# File 'lib/dotstrings/item.rb', line 9 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.
7 8 9 |
# File 'lib/dotstrings/item.rb', line 7 def comment @comment end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
7 8 9 |
# File 'lib/dotstrings/item.rb', line 7 def key @key end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
7 8 9 |
# File 'lib/dotstrings/item.rb', line 7 def value @value end |
Instance Method Details
#==(other) ⇒ Object
15 16 17 |
# File 'lib/dotstrings/item.rb', line 15 def ==(other) eql?(other) end |
#eql?(other) ⇒ Boolean
19 20 21 22 23 24 |
# File 'lib/dotstrings/item.rb', line 19 def eql?(other) other.is_a?(Item) && comment == other.comment && key == other.key && value == other.value end |
#to_s(escape_single_quotes: false, include_comment: true) ⇒ Object
Serializes the item to string.
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/dotstrings/item.rb', line 31 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 |