Last active
December 13, 2017 19:46
-
-
Save Casual3498/577bad9e2028478a83fe7ea50606e617 to your computer and use it in GitHub Desktop.
2lesson
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
filename = 'movies.txt' | |
name_template = 'Max' | |
name_index = 1 | |
rating_index = 7 | |
file = "" | |
filename = ARGV[0] || filename | |
unless File.exist?(filename) | |
puts "File #{filename} not found!" | |
return | |
end | |
File.open(filename) do |file| | |
file.each do |string| | |
string_array = string.split('|') | |
if string_array.length > name_index && | |
string_array[name_index].include?(name_template) | |
result = string_array[name_index] | |
if string_array.length > rating_index && | |
string_array[rating_index].to_f | |
rating = string_array[rating_index].to_f | |
if rating < 8 | |
result += " <8" | |
else | |
result += ' ' + '*'*((rating-8)*10) | |
end | |
end | |
puts result | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment