Skip to content

Instantly share code, notes, and snippets.

@Prigin
Prigin / quick_start.rb
Last active September 23, 2019 16:09
mkdev task
movie = ARGV[0]
list = {"Titanic" => "Titanic is a bad movie",
"Matrix" => "Matrix is a good movie"}
if movie
res = list[movie]
if res
puts res
else
@Prigin
Prigin / quick_start_2.rb
Created September 23, 2019 16:54
mkdev
movie = ARGV[0]
goodlist = ["Braveheart", "Matrix", "Lord os the Rings"]
badlist = ["Twilight", "Titanic"]
if movie
if goodlist.include?(movie)
puts "#{movie} is pretty good."
elsif badlist.include?(movie)
puts "#{movie} is not worth watching."
@Prigin
Prigin / quick_start_3.rb
Created September 25, 2019 01:02
MKDEV
doc = ARGV[0]
def Output (file)
print "[search]> "
@search = gets.chomp # how to avoid THIS?!
file.readlines.each do |line|
line = line.split("|")
if line[1].include?(@search) # how to avoid THIS?!
print line[1] + " | "
@Prigin
Prigin / task2_v1.rb
Created September 25, 2019 12:31
variant 1 (works)
doc = ARGV[0]
print "[search]> "
search = gets.chomp
if doc
if File.exist?(doc)
file = File.open(doc)
else
puts "no such file"
end
else
@Prigin
Prigin / task2_v3.rb
Last active September 25, 2019 14:11
variant 3 (fixed)
doc = ARGV[0]
doc = "movies.txt" if doc == nil
unless File.exist?(doc)
puts "no such file"
exit
end
print "[search]> "; search = "Max"; puts search
@Prigin
Prigin / task2_v3.rb
Created September 25, 2019 14:25
final variant
doc = ARGV[0] || "movies.txt"
unless File.exist?(doc)
puts "no such file"
exit
end
print "[search]> "; search = "Max"; puts search
File.foreach(doc) do |line|
line = line.split("|")
@Prigin
Prigin / task3.rb
Created October 8, 2019 18:24
repeating bad
mas = []
doc = "movies.txt"
syms = [:link, :title, :year, :country,
:date, :genre, :duration,
:rating, :director, :stars]
buff = {}
i = 0
File.foreach(doc) do |line|
line.chomp!
@Prigin
Prigin / task3_v2.rb
Created October 9, 2019 18:30
MKDEV
mas = []
doc = "movies.txt"
syms = [:link, :title, :year, :country,
:date, :genre, :duration,
:rating, :director, :stars]
File.foreach(doc){ |line|
mas.append(syms.zip(line.chomp.split("|")).to_h) }
def Show_em (mas)
@Prigin
Prigin / task3_v3.rb
Last active October 10, 2019 19:03
final(?)
doc = "movies.txt"
syms = [:link, :title, :year, :country,
:date, :genre, :duration,
:rating, :director, :stars]
mas = File.foreach(doc).map{|line| syms.zip(line.chomp.split("|")).to_h}
def Show_em (array_hash)
array_hash.each do |unit|
puts unit[:title] + " (" + unit[:date] + "; " + unit[:genre] +") - " + unit[:duration]
end
@Prigin
Prigin / task4.rb
Created October 13, 2019 00:10
try
require 'csv'
require 'ostruct'
doc = "movies.txt"
syms = [:link, :title, :year, :country,
:date, :genre, :duration,
:rating, :director, :stars]
#mas = OpenStruct.new
mas = CSV.readlines(doc, {headers: syms, col_sep: "|"})
def Show_em (array_hash)