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 'socket' | |
class Connection | |
attr_accessor :buff_in, :buff_out | |
def initialize(sock) | |
@sock = sock | |
@buff_in = Queue.new | |
@buff_out = Queue.new | |
@threads = [thread_rcv, thread_snd] | |
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
class Log | |
def initialize(line = 0, col = 0, line_len = 10, size = 6) | |
@line = line | |
@col = col | |
@buff = [''] * size | |
@line_len = line_len | |
end | |
def push(str) | |
str = str.chomp |
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
# frozen_string_literal: false | |
require 'socket' | |
class Server | |
attr_reader :queue | |
Struct.new('Connection', :nick, :sock, :rcv_thr) | |
def initialize(log, addr = 'localhost', port = 3000) | |
addr.to_s |
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 'socket' | |
class Server | |
attr_reader :queue | |
def initialize(log) | |
@srv_sock = TCPServer.new('localhost', 3000) | |
@srv_sock.listen(2) | |
@queue = Queue.new | |
@log = log | |
@conn_list = [] |
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 '../movie_coll.rb' | |
require 'rspec' | |
chk_list = [:link, :title, :year, :country, :date, | |
:genre, :duration, :rating, :director, :stars] | |
describe MovieCollection do | |
mas = MovieCollection.new('test.txt') | |
chk_list.each do |unit| | |
it "" do |
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 '../movie_coll.rb' | |
check_data = [:link, :title, :year, :country, :date, | |
:genre, :duration, :rating, :director, :stars] | |
check_mas = MovieCollection.new('test.txt') | |
check_data.each do |unit| | |
File.open("test_stats_#{unit}.txt", 'w') do |file| | |
file.puts check_mas.stats(unit) | |
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
require_relative 'movie_coll.rb' | |
def compare (val_mov, film_val) | |
if val_mov.is_a?(Array) | |
val_mov.any?(film_val) | |
else | |
film_val === val_mov | |
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
require_relative 'movie_coll.rb' | |
def compare (obj, hash_val) | |
hash_val = hash_val.to_a | |
param1 = obj.send(hash_val[0]) | |
param2 = hash_val[1] | |
p1 = param1.class | |
p2 = param2.class | |
if (p1 == Array)&&(p2 == Array) |
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_relative 'movie_coll.rb' | |
def filter(unit, mas) | |
unit = unit.to_a.map do |u| | |
if u[1].is_a? Array | |
[u[0], u[1].sort] | |
else | |
u | |
end | |
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
class Movie | |
attr_accessor :link, :title, :year, :country, :date, | |
:genre, :duration,:rating, :director, :stars | |
def initialize (link=nil, title=nil, year=nil, country=nil, date=nil, genre=nil, duration=nil, rating=nil, director=nil, stars=nil) | |
@link = link | |
@title = title | |
@year = year | |
@country = country | |
@date = date |
NewerOlder