Class: Autoini::Pair

Inherits:
AbstractLine show all
Includes:
InlineComment
Defined in:
lib/autoini/pair.rb

Instance Attribute Summary collapse

Attributes included from InlineComment

#comment

Class Method Summary collapse

Instance Method Summary collapse

Methods included from InlineComment

included, #line_comment

Constructor Details

#initialize(key, value) ⇒ Pair

Returns a new instance of Pair.



7
8
9
10
# File 'lib/autoini/pair.rb', line 7

def initialize(key, value)
  @key = key
  @value = value
end

Instance Attribute Details

#keyObject

Returns the value of attribute key.



5
6
7
# File 'lib/autoini/pair.rb', line 5

def key
  @key
end

#valueObject

Returns the value of attribute value.



5
6
7
# File 'lib/autoini/pair.rb', line 5

def value
  @value
end

Class Method Details

.parse(line) ⇒ Object



24
25
26
# File 'lib/autoini/pair.rb', line 24

def self.parse(line)
  Pair.new(line[0], line[2]) if line.length == 3 && line[1] == '='
end

Instance Method Details

#==(e) ⇒ Object



20
21
22
# File 'lib/autoini/pair.rb', line 20

def ==(e)
  e.is_a?(Pair) && e.key == key && e.value == value && e.comment == comment
end

#to_aObject



16
17
18
# File 'lib/autoini/pair.rb', line 16

def to_a
  [key.to_sym, value]
end

#to_sObject



12
13
14
# File 'lib/autoini/pair.rb', line 12

def to_s
  line_comment("#{Autoini.escape(key)}=#{Autoini.escape(value)}")
end