Module: BrBoleto::Helper::FormatValue

Extended by:
FormatValue
Included in:
FormatValue
Defined in:
lib/br_boleto/helper/format_value.rb

Instance Method Summary collapse

Instance Method Details

#string_to_date(value, format = "%d%m%Y") ⇒ Object



12
13
14
15
16
# File 'lib/br_boleto/helper/format_value.rb', line 12

def string_to_date(value, format = "%d%m%Y")
	return value if value.is_a?(Date)
	format = '%d%m%y' if value.strip.size == 6
	begin Date.strptime(value, format) rescue nil end
end

#string_to_float(value) ⇒ Object



6
7
8
9
10
# File 'lib/br_boleto/helper/format_value.rb', line 6

def string_to_float(value)
	return 0 if value.blank?
	return value if value.is_a?(Numeric)
	value.insert(value.size-2, '.').to_f
end