Class: GoShawty::Lyric

Inherits:
Object
  • Object
show all
Defined in:
lib/go_shawty/lyric.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLyric

Returns a new instance of Lyric.



4
5
6
7
# File 'lib/go_shawty/lyric.rb', line 4

def initialize
  song_number = 1 +rand(6)
  get_lyric(song_number)
end

Instance Attribute Details

#album_nameObject

Returns the value of attribute album_name.



2
3
4
# File 'lib/go_shawty/lyric.rb', line 2

def album_name
  @album_name
end

#linesObject

Returns the value of attribute lines.



2
3
4
# File 'lib/go_shawty/lyric.rb', line 2

def lines
  @lines
end

#song_nameObject

Returns the value of attribute song_name.



2
3
4
# File 'lib/go_shawty/lyric.rb', line 2

def song_name
  @song_name
end

Instance Method Details

#get_lyric(song_number) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/go_shawty/lyric.rb', line 10

def get_lyric(song_number)

  url = ""
  lyric_array = []

  case song_number
  when 1
    url = "http://www.allthelyrics.com/lyrics/50_cent/in_da_club_radio_edit-lyrics-899426.html"
    lyric_array = [0,1,2,4,5,7]
  when 2
    url = "http://www.allthelyrics.com/lyrics/50_cent/candy_shop_feat_olivia-lyrics-221387.html"
    lyric_array = [0,1,2,4,5]
  when 3
    url = "http://www.allthelyrics.com/lyrics/50_cent/21_questions-lyrics-751.html"
    lyric_array = [1,2,3,4,5,6,7]
  when 4
    url = "http://www.allthelyrics.com/lyrics/50_cent/pimp_radio_edit-lyrics-899432.html"
    lyric_array = [1,2,4,6,8]
  when 5
    url = "http://www.allthelyrics.com/lyrics/50_cent/just_a_lil_bit_radio-lyrics-1158816.html"
    lyric_array = [0,1,2,3,4,5,6]
  when 6
    url = "http://www.allthelyrics.com/lyrics/50_cent/if_i_cant_clean_version-lyrics-559991.html"
    lyric_array = [0,1,2,3,4,5,6,7,8,9]
  end
  scraped_lyrics = Nokogiri::HTML(open(url))
  lyric_selection = lyric_array.sample
  @lines = scraped_lyrics.css("div.content-text-inner p")[lyric_selection].text
  @song_name = scraped_lyrics.css("div.clear-block h1.page-title").text
  @album_name = scraped_lyrics.css("div.content-text-album").text
end