Class: RubyCue::Index

Inherits:
Object
  • Object
show all
Defined in:
lib/rubycue/index.rb

Constant Summary collapse

SECONDS_PER_MINUTE =
60
FRAMES_PER_SECOND =
75
FRAMES_PER_MINUTE =
FRAMES_PER_SECOND * 60

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value = nil) ⇒ Index

Returns a new instance of Index.



9
10
11
12
13
14
15
16
# File 'lib/rubycue/index.rb', line 9

def initialize(value=nil)
  case value
  when Array
    set_from_array!(value)
  when Integer
    set_from_integer!(value)
  end
end

Instance Attribute Details

#framesObject (readonly)

Returns the value of attribute frames.



7
8
9
# File 'lib/rubycue/index.rb', line 7

def frames
  @frames
end

#minutesObject (readonly)

Returns the value of attribute minutes.



7
8
9
# File 'lib/rubycue/index.rb', line 7

def minutes
  @minutes
end

#secondsObject (readonly)

Returns the value of attribute seconds.



7
8
9
# File 'lib/rubycue/index.rb', line 7

def seconds
  @seconds
end

Instance Method Details

#+(other) ⇒ Object



34
35
36
# File 'lib/rubycue/index.rb', line 34

def +(other)
  self.class.new(carrying_addition(other))
end

#-(other) ⇒ Object



38
39
40
# File 'lib/rubycue/index.rb', line 38

def -(other)
  self.class.new(carrying_subtraction(other))
end

#<(other) ⇒ Object



46
47
48
# File 'lib/rubycue/index.rb', line 46

def <(other)
  self.to_f < other.to_f
end

#==(other) ⇒ Object



50
51
52
# File 'lib/rubycue/index.rb', line 50

def ==(other)
  self.to_a == other.to_a
end

#>(other) ⇒ Object



42
43
44
# File 'lib/rubycue/index.rb', line 42

def >(other)
  self.to_f > other.to_f
end

#eachObject



54
55
56
# File 'lib/rubycue/index.rb', line 54

def each
  to_a.each {|value| yield value }
end

#to_aObject



26
27
28
# File 'lib/rubycue/index.rb', line 26

def to_a
  [@minutes, @seconds, @frames]
end

#to_fObject



18
19
20
# File 'lib/rubycue/index.rb', line 18

def to_f
  ((@minutes * SECONDS_PER_MINUTE) + (@seconds) + (@frames.to_f / FRAMES_PER_SECOND)).to_f
end

#to_iObject



22
23
24
# File 'lib/rubycue/index.rb', line 22

def to_i
  to_f.floor
end

#to_sObject



30
31
32
# File 'lib/rubycue/index.rb', line 30

def to_s
  "#{'%02d' % @minutes}:#{'%02d' % @seconds}:#{'%02d' % @frames}"
end