Class: Animoto::Assets::Song

Inherits:
Base
  • Object
show all
Defined in:
lib/animoto/assets/song.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#source

Instance Method Summary collapse

Constructor Details

#initialize(source, options = {}) ⇒ Assets::Song

Creates a new Song object.

Parameters:

  • source (String)

    the source URL of this song

  • options (Hash{Symbol=>Object}) (defaults to: {})

Options Hash (options):

  • :start_time (Float)

    the time offset in seconds from the beginning of where to start playing this song

  • :duration (Float)

    the length in seconds of how long to play this song

  • :title (String)

    the title of this song. Defaults to being read from the song file’s metadata

  • :artist (String)

    the artist of this song. Defaults to being read from the song file’s metadata



33
34
35
36
37
38
39
# File 'lib/animoto/assets/song.rb', line 33

def initialize source, options = {}
  super
  @start_time = options[:start_time]
  @duration   = options[:duration]
  @title      = options[:title]
  @artist     = options[:artist]
end

Instance Attribute Details

#artistString

The artist of this song. Default to the title read from the metadata of the source file.

Returns:

  • (String)


22
23
24
# File 'lib/animoto/assets/song.rb', line 22

def artist
  @artist
end

#durationFloat

The duration in seconds of how long this song should play.

Returns:

  • (Float)


12
13
14
# File 'lib/animoto/assets/song.rb', line 12

def duration
  @duration
end

#start_timeFloat

The offset in seconds from the beginning denoting where to start using this song in the video.

Returns:

  • (Float)


8
9
10
# File 'lib/animoto/assets/song.rb', line 8

def start_time
  @start_time
end

#titleString

The title of this song. Defaults to the title read from the metadata of the source file.

Returns:

  • (String)


17
18
19
# File 'lib/animoto/assets/song.rb', line 17

def title
  @title
end

Instance Method Details

#to_hashHash{String=>Object}

Returns a representation of this Song as a Hash.

Returns:

  • (Hash{String=>Object})

    this asset as a Hash

See Also:



45
46
47
48
49
50
51
52
# File 'lib/animoto/assets/song.rb', line 45

def to_hash
  hash = super
  hash['start_time'] = start_time if start_time
  hash['duration'] = duration if duration
  hash['title'] = title if title
  hash['artist'] = artist if artist
  hash
end