Class: DotStrings::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/dotstrings/item.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#commentObject (readonly)

Returns the value of attribute comment.



5
6
7
# File 'lib/dotstrings/item.rb', line 5

def comment
  @comment
end

#keyObject (readonly)

Returns the value of attribute key.



5
6
7
# File 'lib/dotstrings/item.rb', line 5

def key
  @key
end

#valueObject (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