This file contains 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
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) |
This file contains 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
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] |
This file contains 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
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| |
This file contains 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
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 |
This file contains 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
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} |
This file contains 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
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| |
This file contains 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
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)} |
This file contains 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
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: "|") |
This file contains 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
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) |
This file contains 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
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 |