Skip to content

Instantly share code, notes, and snippets.

@Casual3498
Last active December 13, 2017 19:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Casual3498/577bad9e2028478a83fe7ea50606e617 to your computer and use it in GitHub Desktop.
Save Casual3498/577bad9e2028478a83fe7ea50606e617 to your computer and use it in GitHub Desktop.
2lesson
#!/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