Module: FormattedLength
- Defined in:
- lib/formatted_length/railtie.rb,
lib/formatted_length/version.rb,
lib/formatted_length/model_additions.rb,
lib/formatted_length/formatted_length.rb
Defined Under Namespace
Modules: ModelAdditions
Classes: Railtie
Constant Summary
collapse
- VERSION =
"0.0.7"
Class Method Summary
collapse
Class Method Details
12
13
14
15
16
17
18
19
20
|
# File 'lib/formatted_length/formatted_length.rb', line 12
def self.format_to_i(value)
result = 0
unless value.nil?
if (match = /((\d+):)?(\d+):(\d+)/.match(value))
result = match[2].to_i * 3600 + match[3].to_i * 60 + match[4].to_i
end
end
result
end
|
2
3
4
5
6
7
8
9
10
|
# File 'lib/formatted_length/formatted_length.rb', line 2
def self.format_to_s(value)
value = value || 0
hours = value / 3600
minutes = (value / 60) % 60
seconds = value % 60
result = "%02d" % minutes + ":%02d" % seconds
result = "#{hours}:#{result}" if hours > 0
result
end
|