Class: Lomax::CommandLineInterface

Inherits:
Object
  • Object
show all
Defined in:
lib/lomax/command_line_interface.rb

Instance Method Summary collapse

Instance Method Details

#display_placesObject



3
4
5
6
7
8
9
10
# File 'lib/lomax/command_line_interface.rb', line 3

def display_places
  places = Lomax::Scraper.get_places
  places.each do |place| 
    puts place.name
  end
  puts
  puts
end

#display_recordings(place) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/lomax/command_line_interface.rb', line 12

def display_recordings(place)
  puts
  puts
  recordings = Lomax::Scraper.get_recordings(place)
  recordings.each do |recording|
    puts recording.title, recording.date
    puts recording.contributors, recording.place.name
    puts
    puts
  end
  return recordings
end

#nonce_listObject



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/lomax/command_line_interface.rb', line 115

def nonce_list
  places = Lomax::Place.all
  places.each do |place| 
    recordings = Lomax::Scraper.get_recordings(place)
    recordings.each do |recording|
      title_array = recording.split_recording
      title_array.each do |title_string|
        nonce = Lomax::Scraper.get_li_s(title_string)
        if nonce == true
          puts place.name + "  '#{title_string}'"
      
        end
      end
    end
  end
end

#place_validationObject



38
39
40
41
42
43
44
45
46
47
# File 'lib/lomax/command_line_interface.rb', line 38

def place_validation
  puts
  display_places
  city_answer = gets.chomp #it is a string
  places_array = Lomax::Place.all 
  choice = places_array.detect do |place|
    place.name.downcase == city_answer.downcase
  end
  return choice #is a place object
end

#runObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/lomax/command_line_interface.rb', line 51

def run
  puts
  puts"Hey! You're at the Library of Congress' Alan Lomax Collection of Michigan Recordings!" 
  puts
  puts"Here's a list of the Michigan cities from which Mr.Lomax collected recordings." 
  puts
  puts"Type the name of a city to view all the recordings he made there."
  puts 
  puts
  
  flag = nil
  while flag == nil #these two lines basically say, "if everything remians as it now is..."
    flag = place_validation
    if flag != nil
      recordings = display_recordings(flag) #array of recording objects
      titles_array = recordings.collect do|recording| 
        recording.title
      end
      joined_titles = titles_array.join(",")
        
      puts 
      puts
      puts"Would you like to see if there are any other available recordings of one of these songs on record?"
      puts
      puts "If so, I can access All Music's archive to return all the other known recordings of that song, including the  artist(s) who recorded it, the album and label it first appeared on, and the year it was first recorded by that artist. And I'll do it in chronological order." 
      puts
      puts "Type the name of a song you want to investigate, or type no, if you want to return to the beginning, with the original list of cities."
      puts
  
      title = gets.strip

      if title.downcase == "no" 
        run
      else

        title = valid_song_title?(title,joined_titles) 
      
        all_music_return = Lomax::Scraper.get_all_music_songs_of(title)
      #returns song hashes array with all the stuff anyone wants to know about other recordings.
      
        if all_music_return.length == 0
          puts
          puts "Alan Lomax's field recording is the only available recording of this tune."
          puts
        else
          all_music_return.sort_by! {|hash| hash[:year]}
          all_music_return.each do |item|
          puts "\ntitle: '#{item[:title]}'\nperformers: #{item[:performers]}\ncomposers: #{item[:composers]}\nyear recorded: #{item[:year]}\nalbum: #{item[:album]}\nlabel: #{item[:label]}\n"
          end
        end
      end

# maybe make an option to choose another song from that city?

    else 
      puts "Alan Lomax didn't record anything in that city, at least not according to the Library of Congress' Collections. Choose a city from the list this time."
    end
  end
      
  see_recordings_other_city?

end

#see_recordings_other_city?Boolean

Returns:

  • (Boolean)


132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/lomax/command_line_interface.rb', line 132

def see_recordings_other_city? 
  puts
  puts
  puts "Would you like to see the recordings from another city in Michigan?"
  puts

  answer = gets.chomp

  if answer.downcase == "yes"       
    run    
  else     
    puts "Before you go, would you like to see a list of all the nonce songs (songs of which this field recording is the only likely recording ever made) in the Alan Lomax Collection of Michigan Recordings?"

    answer = gets.chomp
    if answer == "yes"     
     nonce_list
    end
    puts
    puts "See you next time, and keep singing!"
  
  end
end

#valid_song_title?(title, joined_titles) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/lomax/command_line_interface.rb', line 25

def valid_song_title?(title,joined_titles)
  flag = true 
  while flag == true
    if joined_titles.downcase.include?(title.downcase)
      flag = false
    else
    puts "Please enter a valid song title."
    title = gets.strip
    end
  end
  return title
end