Class: MultimediaParadise::LongFormatToMillisecondsConverter
- Inherits:
-
Object
- Object
- MultimediaParadise::LongFormatToMillisecondsConverter
show all
- Defined in:
- lib/multimedia_paradise/time/long_format_to_milliseconds_converter.rb
Overview
Constant Summary
collapse
- DEFAULT_INPUT =
'00:00:33.55'
- UNITS_IN_MS =
{
0 => 3600000, 1 => 60000, 2 => 1000 }
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/multimedia_paradise/time/long_format_to_milliseconds_converter.rb', line 40
def initialize(
optional_input = ARGV,
run_already = true
)
reset
set_input(
optional_input
)
run if run_already
end
|
Class Method Details
.[](i = ARGV) ⇒ Object
162
163
164
|
# File 'lib/multimedia_paradise/time/long_format_to_milliseconds_converter.rb', line 162
def self.[](i = ARGV)
new(i).result? end
|
Instance Method Details
#add(i) ⇒ Object
121
122
123
|
# File 'lib/multimedia_paradise/time/long_format_to_milliseconds_converter.rb', line 121
def add(i) set_ms(@ms.to_f + i.to_f)
end
|
#determine_ms ⇒ Object
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/multimedia_paradise/time/long_format_to_milliseconds_converter.rb', line 83
def determine_ms
if input?.to_s.include? ':'
@ms = input?.split(':').each_with_index.map {|d, i|
if i == 2 d = d.gsub(/,/,'.') if d.include? ','
end
d.to_f * UNITS_IN_MS[i]
}.reduce(:+).to_i.to_s else
@ms = input?
end
end
|
99
100
101
|
# File 'lib/multimedia_paradise/time/long_format_to_milliseconds_converter.rb', line 99
def input?
@input
end
|
#ms? ⇒ Boolean
Also known as:
ms
106
107
108
|
# File 'lib/multimedia_paradise/time/long_format_to_milliseconds_converter.rb', line 106
def ms?
@ms
end
|
#output_result ⇒ Object
135
136
137
|
# File 'lib/multimedia_paradise/time/long_format_to_milliseconds_converter.rb', line 135
def output_result
e @ms
end
|
#output_result_in_seconds ⇒ Object
#
output_result_in_seconds
#
128
129
130
|
# File 'lib/multimedia_paradise/time/long_format_to_milliseconds_converter.rb', line 128
def output_result_in_seconds
e @ms.to_f / 1000
end
|
#reset ⇒ Object
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/multimedia_paradise/time/long_format_to_milliseconds_converter.rb', line 54
def reset
@ms = 0.0
@input = nil
end
|
#result? ⇒ Boolean
Also known as:
result
142
143
144
|
# File 'lib/multimedia_paradise/time/long_format_to_milliseconds_converter.rb', line 142
def result?
@ms
end
|
#run ⇒ Object
149
150
151
152
|
# File 'lib/multimedia_paradise/time/long_format_to_milliseconds_converter.rb', line 149
def run
determine_ms
end
|
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/multimedia_paradise/time/long_format_to_milliseconds_converter.rb', line 68
def set_input(i = DEFAULT_INPUT)
i = i.join(' ') if i.is_a? Array
i = DEFAULT_INPUT if i.nil?
i = i.to_s.dup.strip
if i.include? 'std'
i = (i.gsub(/std/,'').to_f * 60) * 1000
elsif i.include? 'minuten'
i = (i.gsub(/minuten/,'').to_f * 60) * 1000 end
@input = i
end
|
#set_ms(i = 0.0) ⇒ Object
113
114
115
116
|
# File 'lib/multimedia_paradise/time/long_format_to_milliseconds_converter.rb', line 113
def set_ms(i = 0.0)
i = i.to_f if i.is_a? String
@ms = i
end
|