Class: BlueConductor::Producer

Inherits:
Object
  • Object
show all
Defined in:
lib/blue_conductor/producer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(band, record_title) ⇒ Producer

Returns a new instance of Producer.



6
7
8
9
10
11
12
# File 'lib/blue_conductor/producer.rb', line 6

def initialize(band, record_title)
  @band = band
  @title = record_title
  @songs = nil
  @image = ''
  @error = ''
end

Instance Attribute Details

#bandObject (readonly)

Returns the value of attribute band.



3
4
5
# File 'lib/blue_conductor/producer.rb', line 3

def band
  @band
end

#errorObject (readonly)

Returns the value of attribute error.



3
4
5
# File 'lib/blue_conductor/producer.rb', line 3

def error
  @error
end

#imageObject (readonly)

Returns the value of attribute image.



3
4
5
# File 'lib/blue_conductor/producer.rb', line 3

def image
  @image
end

#parserObject

Returns the value of attribute parser.



4
5
6
# File 'lib/blue_conductor/producer.rb', line 4

def parser
  @parser
end

#requestObject

Returns the value of attribute request.



4
5
6
# File 'lib/blue_conductor/producer.rb', line 4

def request
  @request
end

#songsObject (readonly)

Returns the value of attribute songs.



3
4
5
# File 'lib/blue_conductor/producer.rb', line 3

def songs
  @songs
end

#titleObject (readonly)

Returns the value of attribute title.



3
4
5
# File 'lib/blue_conductor/producer.rb', line 3

def title
  @title
end

#url_generatorObject

Returns the value of attribute url_generator.



4
5
6
# File 'lib/blue_conductor/producer.rb', line 4

def url_generator
  @url_generator
end

Instance Method Details

#record!Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/blue_conductor/producer.rb', line 14

def record!
  url       = url_generator.generate(self)
  html      = request.fetch(url)
  tracklist = parser.parse(html)

  if tracklist.nil? || tracklist.empty?
    @error = 'The album requested is not available || there was a spelling error'
  else
    @image = parser.parse_image(html)

    @songs = tracklist.map do |song|
      BlueConductor.song_for(@band, song)
    end
  end

  self
end