Class: KeyValueName::BooleanMarshaler

Inherits:
MarshalerBase show all
Defined in:
lib/key_value_name/marshalers/boolean_marshaler.rb

Overview

Read and write a boolean flag.

Instance Method Summary collapse

Methods inherited from MarshalerBase

#initialize

Constructor Details

This class inherits a constructor from KeyValueName::MarshalerBase

Instance Method Details

#generate(value) ⇒ Object



16
17
18
# File 'lib/key_value_name/marshalers/boolean_marshaler.rb', line 16

def generate(value)
  value ? 'true' : 'false'
end

#matcherObject



8
9
10
# File 'lib/key_value_name/marshalers/boolean_marshaler.rb', line 8

def matcher
  /true|false/i
end

#parse(string) ⇒ Object



12
13
14
# File 'lib/key_value_name/marshalers/boolean_marshaler.rb', line 12

def parse(string)
  string == 'true'
end

#to_comparable(value) ⇒ Object



20
21
22
# File 'lib/key_value_name/marshalers/boolean_marshaler.rb', line 20

def to_comparable(value)
  value ? 1 : 0
end