Skip to content

Instantly share code, notes, and snippets.

@Prigin
Prigin / mov_col.rb
Last active October 23, 2019 13:57
task 5
load 'movie.rb'
class MovieCollection
attr_accessor :all
def read(unit)
@all = File.readlines(unit).map{|line| Movie.new( *line.chomp.split("|") ) }
end
def sort_by(field)
@Prigin
Prigin / 5_v1.rb
Created October 21, 2019 01:09
task 5
class Movie
attr_accessor :link, :title, :year, :country, :date,
:genre, :duration,:rating, :director, :stars
def initialize (unit)
@link = unit[0]
@title = unit[1]
@year = unit[2]
@country = unit[3]
@date = unit[4]
@genre = unit[5]
@Prigin
Prigin / 4_final.rb
Last active October 18, 2019 15:01
final(?) task 4
require 'csv'
require 'ostruct'
doc = "movies.txt"
syms = [:link, :title, :year, :country,
:date, :genre, :duration,
:rating, :director, :stars]
mas = CSV.readlines(doc, headers: syms, col_sep: "|").map{|unit| OpenStruct.new(unit.to_h)}
def Show_em (array_hash)
array_hash.each do |unit|
@Prigin
Prigin / bit_1.rb
Created October 17, 2019 19:34
bit of code
months = mas.each_with_object(
[["jan", 0], ["feb", 0], ["mar", 0],
["apr", 0], ["may", 0], ["jun", 0],
["jul", 0], ["aug", 0], ["sep", 0],
["oct", 0], ["nov", 0], ["dec", 0]]) do |base, unit|
buff = base.date.split("-")[1]
unit[buff.to_i-1][1] += 1 if buff != nil
end
@Prigin
Prigin / bit.rb
Created October 17, 2019 17:01
bit of code
months = [["jan", 0],["feb", 0], ["mar", 0], ["apr", 0], ["may", 0], ["jun", 0],
["jul", 0], ["aug", 0], ["sep", 0], ["oct", 0], ["nov", 0], ["dec", 0]]
mas.each do |unit|
months.each_index{|index| months[index][1] += 1 if index + 1 == unit.date.split("-")[1].to_i}
end
months.each{|unit| p unit}
@Prigin
Prigin / 4_v4.rb
Last active October 15, 2019 15:56
task 4
require 'csv'
require 'ostruct'
doc = "movies.txt"
syms = [:link, :title, :year, :country,
:date, :genre, :duration,
:rating, :director, :stars]
mas = CSV.readlines(doc, headers: syms, col_sep: "|").map{|unit| OpenStruct.new(unit.to_h)}
def Show_em (array_hash)
array_hash.each do |unit|
@Prigin
Prigin / 4_v3.rb
Created October 14, 2019 16:15
task 4
require 'csv'
require 'ostruct'
doc = "movies.txt"
syms = [:link, :title, :year, :country,
:date, :genre, :duration,
:rating, :director, :stars]
mas = CSV.readlines(doc, headers: syms, col_sep: "|").map{|unit| OpenStruct.new(unit.to_h)}
@Prigin
Prigin / 4_v2.rb
Created October 13, 2019 22:47
task 4
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: "|")
@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)
@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