├── .gitignore
├── 2-first_program
└── my_add_five_to_six.rb
├── 3-classes
├── person-classes
│ ├── people.rb
│ ├── people1.rb
│ ├── people1a.rb
│ ├── people2.rb
│ └── people3.rb
├── pract3
│ ├── best_num_program
│ │ ├── hi_mate.rb
│ │ ├── secret.rb
│ │ └── try_again.rb
│ └── family
│ │ ├── do_each_fam.rb
│ │ ├── each_fam.rb
│ │ ├── family.rb
│ │ └── type.rb
├── require-class
│ ├── error.rb
│ ├── name1.rb
│ ├── name2.rb
│ └── thanks.rb
└── simple_io
│ ├── info.txt
│ └── reader.rb
├── 4-moreNuts
├── 15436488.zip
├── classo.rb
├── iterators
│ ├── 1
│ ├── combo.rb
│ ├── food.rb
│ └── weird.rb
├── pract4
│ ├── book.rb
│ ├── library.rb
│ ├── top.rb
│ └── user.rb
└── vars
│ ├── ruby_vars.txt
│ └── vars.rb
├── 5-iTunesTings
├── 15436488.zip
└── itunesSystem
│ ├── .DS_Store
│ ├── .idea
│ ├── .name
│ ├── encodings.xml
│ ├── iTunesv1.clean.iml
│ ├── misc.xml
│ ├── modules.xml
│ ├── vcs.xml
│ └── workspace.xml
│ ├── actor.rb
│ ├── album.rb
│ ├── error.rb
│ ├── itunes.rb
│ ├── owners.csv
│ ├── reader.rb
│ ├── song.rb
│ ├── songs.csv
│ └── utilities.rb
├── 6-Mods-Inherit-n-iTsV2
├── ignore
│ ├── RubyLect6.progs
│ │ ├── .DS_Store
│ │ ├── .idea
│ │ │ ├── .name
│ │ │ ├── RubyLect6.progs.iml
│ │ │ ├── encodings.xml
│ │ │ ├── misc.xml
│ │ │ ├── modules.xml
│ │ │ ├── vcs.xml
│ │ │ └── workspace.xml
│ │ ├── inherit.rb
│ │ ├── inherit_vars.rb
│ │ └── logik.rb
│ └── itunesSystem_moded.zip
└── itunesSystem_moded
│ ├── abc
│ └── inherit.rb
│ ├── actor.rb
│ ├── album.rb
│ ├── data.rb
│ ├── error.rb
│ ├── itunes.rb
│ ├── owners.csv
│ ├── predicate.rb
│ ├── reader.rb
│ ├── song.rb
│ ├── songs.csv
│ ├── txt.txt
│ └── utilities.rb
├── 7-equa-mod-n-webStuff
├── docNoko.rb
└── testNoko.rb
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | *.gem
2 | *.rbc
3 | /.config
4 | /coverage/
5 | /InstalledFiles
6 | /pkg/
7 | /spec/reports/
8 | /spec/examples.txt
9 | /test/tmp/
10 | /test/version_tmp/
11 | /tmp/
12 |
13 | # Used by dotenv library to load environment variables.
14 | # .env
15 |
16 | # Ignore Byebug command history file.
17 | .byebug_history
18 |
19 | ## Specific to RubyMotion:
20 | .dat*
21 | .repl_history
22 | build/
23 | *.bridgesupport
24 | build-iPhoneOS/
25 | build-iPhoneSimulator/
26 |
27 | ## Specific to RubyMotion (use of CocoaPods):
28 | #
29 | # We recommend against adding the Pods directory to your .gitignore. However
30 | # you should judge for yourself, the pros and cons are mentioned at:
31 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
32 | #
33 | # vendor/Pods/
34 |
35 | ## Documentation cache and generated files:
36 | /.yardoc/
37 | /_yardoc/
38 | /doc/
39 | /rdoc/
40 |
41 | ## Environment normalization:
42 | /.bundle/
43 | /vendor/bundle
44 | /lib/bundler/man/
45 |
46 | # for a library or gem, you might want to ignore these files since the code is
47 | # intended to run in multiple environments; otherwise, check them in:
48 | # Gemfile.lock
49 | # .ruby-version
50 | # .ruby-gemset
51 |
52 | # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
53 | .rvmrc
54 |
55 | # Used by RuboCop. Remote config files pulled in from inherit_from directive.
56 | # .rubocop-https?--*
57 |
58 | # files to ignore
59 | labs/
60 | lab1/
61 | lab2/
62 | RubyLect3.Prac3.pdf
63 | 3-classes/ignore/
64 | 4-moreNuts/ignore/
65 | 5-iTunesTings/ignore/
66 | 6-Modules-n-iTunesV2/ignore/
67 | 7-equa-mod-n-webStuff/ignore/
68 |
--------------------------------------------------------------------------------
/2-first_program/my_add_five_to_six.rb:
--------------------------------------------------------------------------------
1 | def my_add_five_to_six
2 | p 5+6
3 | end
4 |
5 | my_add_five_to_six
6 |
--------------------------------------------------------------------------------
/3-classes/person-classes/people.rb:
--------------------------------------------------------------------------------
1 | class Person
2 | def fname
3 | @fname
4 | end
5 |
6 | def give_fname(name)
7 | @fname = name
8 |
9 | end
10 |
11 | def lname
12 | @lname
13 | end
14 |
15 | def give_lname(name)
16 | @lname = name
17 | end
18 | end
19 |
20 | inst1 = Person.new
21 | inst1.give_fname("mark")
22 | inst1.give_lname("kean")
23 |
24 | p inst1
25 |
--------------------------------------------------------------------------------
/3-classes/person-classes/people1.rb:
--------------------------------------------------------------------------------
1 | class Person
2 | attr_accessor :fname, :lname
3 | end
4 |
5 | inst1 = Person.new
6 | inst1.fname = "mark"
7 | inst1.lname = "keane"
8 |
9 | inst2 = Person.new
10 | inst2.fname = "kyle"
11 | inst2.lname = "rogers"
12 |
13 | inst3 = Person.new
14 | inst3.fname = "george"
15 | inst3.lname = "micheals"
16 |
17 | p inst3
18 | puts inst3
19 |
--------------------------------------------------------------------------------
/3-classes/person-classes/people1a.rb:
--------------------------------------------------------------------------------
1 | class Person
2 | attr_accessor :name1, :name2
3 |
4 | def initialize(fname, lname)
5 | @fname = fname
6 | @lname = lname
7 | end
8 | end
9 |
10 | inst1 = Person.new("dude","yes")
11 | inst2 = Person.new("dude","no")
12 | inst3 = Person.new("bro","please")
13 |
14 | p inst1
15 | inst1.name1 = "bill"
16 | p inst1
17 |
18 |
--------------------------------------------------------------------------------
/3-classes/person-classes/people2.rb:
--------------------------------------------------------------------------------
1 | class Person
2 | attr_accessor :fname, :lname
3 |
4 | def initialize(fname, lname)
5 | @fname = fname
6 | @lname = lname
7 | end
8 | def to_s
9 | "hi " + @fname +"," +@lname
10 | end
11 | end
12 |
13 | inst2 = Person.new("mark", "koo")
14 | p inst2
15 | p inst2.to_s
16 | puts inst2
17 |
18 |
--------------------------------------------------------------------------------
/3-classes/person-classes/people3.rb:
--------------------------------------------------------------------------------
1 | class Person
2 | attr_accessor :fname, :lname, :age
3 |
4 | def initialize(fname, lname)
5 | @fname = fname
6 | @lname = lname
7 | end
8 | def to_s
9 | "hi " + @fname +"," +@lname
10 | end
11 |
12 | def self.make_person(fnme, lnme, age)
13 | new_person =Person.new(fnme, lnme)
14 | new_person.age = age
15 | new_person
16 | end
17 |
18 | def age_person
19 | self.age = self.age + 1
20 | @age
21 | end
22 |
23 | end
24 |
25 | mk = Person.make_person("mark", "koo", 45)
26 | p mk
27 | puts mk
28 | p mk.age_person
29 |
30 |
31 |
--------------------------------------------------------------------------------
/3-classes/pract3/best_num_program/hi_mate.rb:
--------------------------------------------------------------------------------
1 | require_relative "try_again"
2 | require_relative "secret"
3 |
4 |
5 | def question_one
6 | puts "answer correct and I'll tell u a secret"
7 | puts "what is the best number, range 1-10"
8 | answer = gets
9 | if answer_is_ok?(answer.chomp.to_i)
10 | then question_two
11 | end
12 | end
13 |
14 | def question_two
15 | puts "best index? range 1-10"
16 | answer2 = gets
17 | if answer_is_ok?(answer2.chomp.to_i)
18 | then secret("my favourite number is 8")
19 | end
20 | end
21 |
22 | def answer_is_ok?(answero)
23 | p "your answer was " + answero.to_s
24 | if answero == 7
25 | then true
26 | else try_again
27 | end
28 | end
29 |
30 | question_one
31 |
32 |
--------------------------------------------------------------------------------
/3-classes/pract3/best_num_program/secret.rb:
--------------------------------------------------------------------------------
1 | def secret(sp_message)
2 | puts "\n**De_Secret**:#{sp_message}.\n"
3 | end
4 |
--------------------------------------------------------------------------------
/3-classes/pract3/best_num_program/try_again.rb:
--------------------------------------------------------------------------------
1 |
2 | def try_again
3 | puts "how did ya get that wrong?"
4 | puts "try again!"
5 | question_one
6 | end
7 |
8 |
--------------------------------------------------------------------------------
/3-classes/pract3/family/do_each_fam.rb:
--------------------------------------------------------------------------------
1 | require_relative "family"
2 |
3 | fm1 = FamilyMember.new("joe", "male", "married", 35, "y")
4 | fm2 = FamilyMember.new("mary", "female", "married", 36, "y")
5 | fm3 = FamilyMember.new("kyle", "male", "single", 15, "n")
6 | fm4 = FamilyMember.new("sarah", "female", "single", 5, "n")
7 |
8 | family = [fm1,fm2,fm3,fm4]
9 |
10 | family.each do |fam_mem|
11 | puts "'name: ' #{fam_mem.name} 'sex: ' #{fam_mem.sex} 'status: ' #{fam_mem.status} 'age: '#{fam_mem.age} 'children: '#{fam_mem.children}"
12 | end
13 |
14 |
--------------------------------------------------------------------------------
/3-classes/pract3/family/each_fam.rb:
--------------------------------------------------------------------------------
1 | require_relative "family"
2 |
3 | fm1 = FamilyMember.new("joe", "male", "married", 35, "y")
4 | fm2 = FamilyMember.new("mary", "female", "married", 36, "y")
5 | fm3 = FamilyMember.new("kyle", "male", "single", 15, "n")
6 | fm4 = FamilyMember.new("sarah", "female", "single", 5, "n")
7 |
8 | family = [fm1,fm2,fm3,fm4]
9 |
10 | family.each {|fam_mem|
11 | if fam_mem.age < 18
12 | then puts "#{fam_mem.name.chomp}" + " is underage"
13 |
14 | elsif fam_mem.age > 18 && fam_mem.status == "single"
15 | then puts "#{fam_mem.name.chomp}" + " is single"
16 |
17 | else
18 | puts "#{fam_mem.name.chomp}" + " is married"
19 | end }
20 |
21 |
--------------------------------------------------------------------------------
/3-classes/pract3/family/family.rb:
--------------------------------------------------------------------------------
1 | class FamilyMember
2 | attr_accessor :name, :sex, :status, :age, :children;
3 |
4 | def initialize(name, sex, status, age, children)
5 | @name = name
6 | @sex = sex
7 | @age = age
8 | @status = status
9 | @children = children
10 | end
11 | # the person is a parent if they are the eldest and marriage status is "y"
12 | #
13 | def parent?
14 | name = @name
15 | sex = @sex
16 | age_of_pers = @age
17 | married_yn = @status
18 | children_yn = @children
19 |
20 | if children_yn == "y" && sex == "male"
21 | then puts name.chomp + " is a 'father' parent type family memeber"
22 | true
23 |
24 | elsif children_yn == "y" && sex =="female"
25 | then puts name.chomp + " is a 'mother' of the parent type of a family tree"
26 | true
27 |
28 | else
29 | child?
30 | false
31 |
32 | end
33 | end
34 |
35 | def child?
36 | name = @name
37 | age_of_pers = @age
38 | married_yn = @status
39 | children_yn = @children
40 | sex = @sex
41 |
42 | if children_yn == "n" && sex == "male"
43 | then puts name.chomp + " is a 'son' type of family sect of benders"
44 | true
45 |
46 | elsif children_yn == "n" && sex == "female"
47 | then puts name.chomp + " is a 'daughter' sort of family member"
48 | true
49 |
50 | else
51 | parent?
52 | false
53 |
54 | end
55 | end
56 |
57 | end
58 |
59 |
--------------------------------------------------------------------------------
/3-classes/pract3/family/type.rb:
--------------------------------------------------------------------------------
1 | require_relative 'family'
2 |
3 | fm1 = FamilyMember.new("joe", "male", "married", 35, "y")
4 | fm2 = FamilyMember.new("mary", "female", "married", 36, "y")
5 | fm3 = FamilyMember.new("kyle", "male", "single", 15, "n")
6 | fm4 = FamilyMember.new("sarah", "female", "single", 5, "n")
7 |
8 | fm1.parent?
9 | p fm2.child?
10 | fm3.parent?
11 | fm4.parent?
12 |
13 |
--------------------------------------------------------------------------------
/3-classes/require-class/error.rb:
--------------------------------------------------------------------------------
1 | def error(sp_message)
2 | puts "\n**ERROR**:#{sp_message}.\n"
3 | end
4 |
5 |
--------------------------------------------------------------------------------
/3-classes/require-class/name1.rb:
--------------------------------------------------------------------------------
1 | def get_name
2 | puts "What is your surname?:"
3 | name = gets
4 | print_thanks
5 | if check_name_ok?(name)
6 | then print_new_name(name)
7 | end
8 | end
9 |
10 | def print_thanks
11 | puts "Thanks for that."
12 | end
13 |
14 | def check_name_ok?(nameo)
15 | if nameo.length > 5
16 | then error("way too long a name")
17 | else true
18 | end
19 | end
20 |
21 | def print_new_name(namer)
22 | newname = namer.chomp + "po"
23 | puts newname
24 | end
25 |
26 | def error(sp_message)
27 | puts "\n**ERROR**:#{sp_message}.\n"
28 | end
29 |
30 | get_name
31 |
32 |
33 |
--------------------------------------------------------------------------------
/3-classes/require-class/name2.rb:
--------------------------------------------------------------------------------
1 | require_relative 'thanks'
2 | require_relative 'error'
3 |
4 | def get_name
5 | puts "What is your surname?:"
6 | name = gets
7 | print_thanks
8 | if check_name_ok?(name)
9 | then print_new_name(name)
10 | end
11 | end
12 |
13 | def check_name_ok?(nameo)
14 | if nameo.length > 5
15 | then error("way too long a name")
16 | else true
17 | end
18 | end
19 |
20 | def print_new_name(namer)
21 | newname = namer.chomp.concat("po")
22 | puts "k, yer new name is:"
23 | puts newname
24 | end
25 |
26 | get_name
27 |
28 |
--------------------------------------------------------------------------------
/3-classes/require-class/thanks.rb:
--------------------------------------------------------------------------------
1 | def print_thanks
2 | puts "Thanks for that"
3 | end
4 |
--------------------------------------------------------------------------------
/3-classes/simple_io/info.txt:
--------------------------------------------------------------------------------
1 | This is very important information :
2 | 1. I like ruby
3 | 2. Ruby like me
4 | 3. u like ruby
5 | 4. ruby no like u
6 | 5. sorry
7 |
8 | end
9 |
--------------------------------------------------------------------------------
/3-classes/simple_io/reader.rb:
--------------------------------------------------------------------------------
1 | filo = File.open("info.txt", "r")
2 | filo.each_line {|line| puts line + " yahoo! "}
3 |
4 |
--------------------------------------------------------------------------------
/4-moreNuts/15436488.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/furious-monkey/rubytest/6fafe0ae63cb110dac249a9d7e388343208227c0/4-moreNuts/15436488.zip
--------------------------------------------------------------------------------
/4-moreNuts/classo.rb:
--------------------------------------------------------------------------------
1 | class Testo
2 | attr_accessor :name, :surname
3 |
4 | def initialize(name, surn)
5 | @name = name
6 | @surname = surn
7 | end
8 |
9 | def man_name
10 | "mr" + @name + @surname
11 | end
12 |
13 | def man_name=(name_array)
14 | @name = name_array[1]
15 | @surname = name_array[2]
16 | end
17 | end
18 |
19 | mark = Testo.new("hassan","ajaj")
20 | p mark.man_name
21 | mark.man_name = ["mr","hassan","bean"]
22 | p mark.man_name
23 |
--------------------------------------------------------------------------------
/4-moreNuts/iterators/1:
--------------------------------------------------------------------------------
1 | def weird(arr1, out=[])
2 | arr1.each {|ele1|
3 | out = puts ele1 + " out"}
4 | out
5 | end
6 |
7 | p weird(["a", "c", "x"])
8 |
--------------------------------------------------------------------------------
/4-moreNuts/iterators/combo.rb:
--------------------------------------------------------------------------------
1 | def combos(array1, array2, n=6)
2 | array1.each do |ele1|
3 | array2.each do |ele2|
4 | n+=1
5 | puts "#{ele1}, #{ele2}, on #{n}"
6 | end
7 | end
8 | end
9 |
10 | combos(["a","b","c"],[1,2,3])
11 |
--------------------------------------------------------------------------------
/4-moreNuts/iterators/food.rb:
--------------------------------------------------------------------------------
1 | class Sausage
2 | attr_accessor :name, :made_of, :taste
3 |
4 | def initialize(name, made, tasty)
5 | @name, @made_of, @taste = name, made, tasty
6 | end
7 |
8 | def self.judge_all(*sausies)
9 | sausies.each do |saussy|
10 | if saussy.made_of == "pork"
11 | then saussy.taste = "haram"
12 | elsif saussy.made_of == "quorn"
13 | then saussy.taste = "yummy"
14 | else saussy.taste = " dont know" end #this end is for if
15 | end #this end if for do
16 | end
17 | end
18 |
19 | saus1 = Sausage.new("selbys","pork", nil)
20 | saus2 = Sausage.new("grandby","quorn",nil)
21 | saus3 = Sausage.new("blalong", "beef",nil)
22 | p saus1
23 | p saus2
24 | Sausage.judge_all(saus1,saus2,saus3)
25 | p saus1
26 | p saus2
27 |
28 |
--------------------------------------------------------------------------------
/4-moreNuts/iterators/weird.rb:
--------------------------------------------------------------------------------
1 | def weird(arr1, out=[])
2 | arr1.each {|ele1|
3 | out = puts ele1 + " is out"}
4 | out.to_a
5 | end
6 |
7 | p weird(["a", "c", "x"])
8 |
--------------------------------------------------------------------------------
/4-moreNuts/pract4/book.rb:
--------------------------------------------------------------------------------
1 | class Book
2 | attr_accessor :name, :author, :publisher, :id, :fine, :genre, :avail
3 |
4 | def initialize(name, author, publisher, id, fine, genre, avail)
5 | @name = name;
6 | @author = author;
7 | @publisher = publisher;
8 | @id = id;
9 | @fine = fine;
10 | @genre = genre;
11 | @avail = avail;
12 | end
13 |
14 | def book_name
15 | puts "The " + @name
16 | end
17 | #make this an input function? maybe for fun later
18 | def info
19 | puts " BOOK Info"
20 | yield
21 | puts "THEY CALL IT"
22 | puts "The " + @name
23 | yield
24 | puts "AUTHOR"
25 | puts "The " + @author
26 | yield
27 | puts "FROM"
28 | puts "The " + @genre + "section"
29 | yield
30 | end
31 |
32 | def book_avail?
33 |
34 | if self.avail>1
35 | puts " "
36 | puts "book is available"
37 | true
38 | else
39 | puts " "
40 | puts "sorry this book is all borrowed"
41 | false
42 | end
43 | end
44 |
45 | def this_was_borrowed
46 | self.avail -=1
47 | end
48 |
49 | def many_left
50 | puts "there are " + self.avail.to_s + " copies left"
51 | end
52 |
53 | end
54 |
55 |
--------------------------------------------------------------------------------
/4-moreNuts/pract4/library.rb:
--------------------------------------------------------------------------------
1 | #library(name, address, members, books, borrowed, avail)
2 |
3 | class Library
4 | attr_accessor :name, :address, :members, :book, :borrowed, :avail
5 |
6 | def initialize(name, address, members, book, borrowed, avail)
7 | @name = name;
8 | @address = address;
9 | @members = [];
10 | @book = [];
11 | @borrowed = borrowed;
12 | @avail = avail;
13 | end
14 |
15 | def info
16 | puts " LIBRARY info"
17 | yield
18 | puts @name
19 | yield
20 | puts @address
21 | yield
22 | puts "Total books in stock " + @avail.to_s
23 | yield
24 | end
25 |
26 |
27 | def member_borrowed
28 | puts "#{@members.user_name}" + " borrowed "
29 | puts "#{@book.book_name}"
30 | self.borrowed +=1
31 | self.avail -=1
32 | "#{@book.this_was_borrowed}"
33 | "#{@members.borrowed}"
34 | end
35 |
36 | def print_books_avail
37 | puts "total books left " + self.avail.to_s;
38 | end
39 |
40 | end
41 |
42 |
--------------------------------------------------------------------------------
/4-moreNuts/pract4/top.rb:
--------------------------------------------------------------------------------
1 | require_relative 'book'
2 | require_relative 'library'
3 | require_relative 'user'
4 |
5 | #Book(name, author, publisher, id, fine, genre)
6 | book1 = Book.new("Good Book", "Good Author", "Good Publisher",1,200,"Good Books", 10)
7 | book2 = Book.new("Great Book", "Great Author", "Great Publisher",2,300,"Great Books", 5)
8 | book3 = Book.new("Excellent Book", "Excellent Author", "Excellent Publisher",3,20,"Excellent Books", 6)
9 | book4 = Book.new("Marvelous Book", "Marvelous Author", "Marvelous Publisher",4,3999,"Marvelous Books", 0)
10 | book5 = Book.new("Wonderful Book", "Wonderful Author", "Wonderful Publisher",5,200,"Wonderful Books", 5)
11 |
12 | #User(name,address,id,booksborrowed,haircolor);
13 | user1 = User.new("gbaby", "gtown", 001, 3, "red");
14 | user2 = User.new("kbaby", "ktown", 002, 0, "white");
15 | user3 = User.new("lbaby", "ltown", 003, 10, "black");
16 |
17 | #library(name, address, members, books, borrowed, avail)
18 | library = Library.new("THE library", "@library", user1, book1, 13, 26)
19 | library2 = Library.new("THE library", "@library", user2, book1, 13, 26)
20 | library3 = Library.new("THE library", "@library", user3, book1, 13, 26)
21 |
22 | puts " "
23 | library.info {puts "~~~~~~~~~~~ ;) ~~~~~~~~~~"}
24 |
25 | user1.user_info {puts "~~~~~~~~~~~ ;) ~~~~~~~~~~"}
26 |
27 | puts " "
28 |
29 | user2.user_info {puts "~~~~~~~~~~~ ;) ~~~~~~~~~~"}
30 |
31 | puts " "
32 |
33 | user3.user_info {puts "~~~~~~~~~~~ ;) ~~~~~~~~~~"}
34 |
35 | puts " "
36 |
37 |
38 | book1.info {puts "~~~~~~~~~~~ ;) ~~~~~~~~~~"}
39 |
40 | puts " "
41 |
42 | book1.many_left
43 |
44 | if book1.book_avail?
45 | if user1.how_many_u_got?
46 | library.member_borrowed
47 | end
48 | end
49 |
50 | puts " "
51 | library.print_books_avail
52 | puts " "
53 | book1.many_left
54 |
55 | if book1.book_avail?
56 | if user2.how_many_u_got?
57 | library2.member_borrowed
58 | end
59 | end
60 |
61 |
62 | if book1.book_avail?
63 | if user3.how_many_u_got?
64 | library3.member_borrowed
65 | end
66 | end
67 |
68 | puts " "
69 | book1.many_left
70 |
71 |
--------------------------------------------------------------------------------
/4-moreNuts/pract4/user.rb:
--------------------------------------------------------------------------------
1 | class User
2 | attr_accessor :name, :address, :id, :books_boro, :hair_color
3 |
4 | def initialize(name, address, id, books_boro, hair_color)
5 | @name = name;
6 | @address = address;
7 | @id = id;
8 | @books_boro = books_boro;
9 | @hair_color = hair_color;
10 | end
11 |
12 | def user_name
13 | puts "They name is " +@name
14 | end
15 | def user_info
16 | puts " USER INFO "
17 | yield
18 | puts "They name is " + @name
19 | yield
20 | puts "They house is @" + @address
21 | yield
22 | puts "They borrowed: No. of books " + @books_boro.to_s
23 | yield
24 | puts "They hair color " + @hair_color
25 | end
26 |
27 | def how_many_u_got?
28 | if self.books_boro > 5
29 | puts "WARNING: " + @name + " Yo, bring back my books mann"
30 | false
31 | else
32 | puts "PASS: " + @name + " Yes, you may borrow a book dawg"
33 | true
34 | end
35 | end
36 |
37 | def borrowed
38 | self.books_boro +=1
39 | end
40 |
41 | end
42 |
43 |
--------------------------------------------------------------------------------
/4-moreNuts/vars/ruby_vars.txt:
--------------------------------------------------------------------------------
1 | Ruby Vars..
2 |
3 | Local: has letter3, numbers, or _
4 | Global: start with $
5 | Instance: start with @
6 | Class: @@
7 | ** Constants---Class & names: PI, FeetPerM, String, JazzS
8 |
9 |
10 |
--------------------------------------------------------------------------------
/4-moreNuts/vars/vars.rb:
--------------------------------------------------------------------------------
1 | class Visit
2 | @@all= [] #class var initialized
3 | Places = ["berne","venice"] #constant
4 | attr_accessor :place, :person
5 |
6 | def initialize(pl, per)
7 | @place,@person = pl, per
8 | end
9 |
10 | def to_s
11 | puts "#{@person} visited #{@place}"
12 | end
13 |
14 | def all #inst access
15 | @@all
16 | end
17 |
18 | def self.all #class access
19 | @@all
20 | end
21 |
22 | def add_visit_via_instance #inst assign
23 | @@all << self
24 | end
25 |
26 | def self.add_visit_via_class=(inst) #class assign
27 | @@all << inst
28 | end
29 | end
30 |
31 | foo = Visit.new("venice", "ruth_b")
32 | bar = Visit.new("berne", "mark_k")
33 | p foo
34 | p bar
35 |
36 | puts "Value of @@all, found via foo, is now:"
37 | p foo.all
38 | foo.add_visit_via_instance
39 | puts "value of @@all, foound via bar, is now:"
40 | p bar.all
41 | Visit.add_visit_via_class = bar
42 | puts "value of @@all, found via the class, is now:"
43 | p Visit.all
44 | p Visit::Places
45 |
--------------------------------------------------------------------------------
/5-iTunesTings/15436488.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/furious-monkey/rubytest/6fafe0ae63cb110dac249a9d7e388343208227c0/5-iTunesTings/15436488.zip
--------------------------------------------------------------------------------
/5-iTunesTings/itunesSystem/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/furious-monkey/rubytest/6fafe0ae63cb110dac249a9d7e388343208227c0/5-iTunesTings/itunesSystem/.DS_Store
--------------------------------------------------------------------------------
/5-iTunesTings/itunesSystem/.idea/.name:
--------------------------------------------------------------------------------
1 | iTunesv1.clean
--------------------------------------------------------------------------------
/5-iTunesTings/itunesSystem/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/5-iTunesTings/itunesSystem/.idea/iTunesv1.clean.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/5-iTunesTings/itunesSystem/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/5-iTunesTings/itunesSystem/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/5-iTunesTings/itunesSystem/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/5-iTunesTings/itunesSystem/.idea/workspace.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 | false
281 |
282 |
283 |
284 |
285 | 1378474012564
286 | 1378474012564
287 |
288 |
289 |
290 |
291 |
292 |
293 |
294 |
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 |
324 |
325 |
326 |
327 |
328 |
329 |
330 |
331 |
332 |
333 |
334 |
335 |
336 |
337 |
338 |
339 |
340 |
341 |
342 |
343 |
344 |
345 |
346 |
347 |
348 |
349 |
350 |
351 |
352 |
353 |
354 |
355 |
356 |
357 |
358 |
359 |
360 |
361 |
362 |
363 |
364 |
365 |
366 |
367 |
368 |
369 |
370 |
371 |
372 |
373 |
374 |
375 |
376 |
377 |
378 |
379 |
380 |
381 |
382 |
383 |
384 |
385 |
386 |
387 |
388 |
389 |
390 |
391 |
392 |
393 |
394 |
395 |
396 |
397 |
398 |
399 |
400 |
401 |
402 |
403 |
404 |
405 |
406 |
--------------------------------------------------------------------------------
/5-iTunesTings/itunesSystem/actor.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby -w
2 | # ACTOR
3 | # Copyright Mark Keane, All Rights Reserved, 2014
4 |
5 | # Class that encodes details of actors that own songs/albums.
6 | class Actor
7 |
8 | attr_accessor :name, :id
9 | def initialize(name)
10 | @name = name
11 | @id = name.object_id
12 | end
13 |
14 | # Method that prints out the contents of an actor object nicely.
15 |
16 | def to_s
17 | puts "Actor #{@name} has ID: #{@id}.\n"
18 | end
19 |
20 | # Method that checks if an object given to it is an actor.
21 | def isa?
22 | instance_of?(Actor)
23 | end
24 |
25 | # Class method that builds all the actor objects using names originally from owners.csv.
26 | # Recall owners.csv got read into $hash_owners, we recover all the names associated with all
27 | # the song-ids and reduce it to an array of unique owner-name strings. We then use these to build
28 | # actor obejcts using Actor.new. The method returns an array of actor-objects.
29 |
30 | def self.build_all(actors = [])
31 | actor_names = $hash_owners.values.clean_up
32 | actor_names.each {|name| actors << Actor.new(name)}
33 | actors
34 | end
35 |
36 | # Method that takes an actor and allows him/her/it to buy a song; by just adding the persons name to the song.
37 | # Obviously, this should be more complicated, like it should write something to owners.csv too.
38 |
39 | def buys_song(song)
40 | song.owners << (" " + @name)
41 | end
42 |
43 | # Method that takes an actor finds all the songs owned by the actor.
44 | # It returns a array of song objects.
45 |
46 | def what_songs_does_he_own()
47 | $songs.select{|song| song.owners.include?(@name)}
48 | end
49 |
50 | end
51 |
52 |
--------------------------------------------------------------------------------
/5-iTunesTings/itunesSystem/album.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby -w
2 | # ALBUM
3 | # Copyright Mark Keane, All Rights Reserved, 2014
4 | require_relative 'song.rb'
5 | # Class that encodes details of an album.
6 | class Album < Song
7 | attr_accessor :name, :tracks, :length, :artist,:owners, :id
8 | def initialize(name, tracks, length, artist, owners)
9 | @name = name
10 | @tracks = tracks
11 | @length = length
12 | @artist = artist
13 | @owners = owners
14 | @id = name.object_id
15 | end
16 |
17 | # Method that prints out the contents of an album object nicely.
18 | # how do I get then ablum full name and the associated artist??? :((((
19 | def to_s
20 | puts "the album #{@name} by #{@artist}. \n"
21 | end
22 |
23 | # Method that checks if an object given to it is an album.
24 | def isa?
25 | instance_of?(Album)
26 | end
27 |
28 | # Method makes an album object; just uses Album.new; really
29 | # just being a bit explicit and obvious.
30 |
31 | def self.make_album(name,tracks, length, artist, owners)
32 | Album.new(name, tracks, length, artist, owners)
33 | end
34 |
35 | # Class Method that builds albums from song object's contents.
36 | # It returns an array of album objects. It calls another class method that
37 | # builds a single album, given the name of that album.
38 |
39 | def self.build_all(albums = [])
40 | album_names = $songs.uniq{ |song| song.album} #uniq albums from $songs global.
41 |
42 | #calls build for each album name once and appends result
43 | album_names.each do |song| #get each song and build the album from the name
44 | albums << build_an_album_called(song.album)
45 | end
46 | albums
47 | end
48 |
49 | # Class method that takes an album name, it finds all the sounds that are in that album
50 | # builds up arrays of the song-names (tracks), runtimes, artist names. These all get used
51 | # to populate the various attributes of the album object.
52 |
53 | def self.build_an_album_called(album_name)
54 | #get the songs of the album
55 | songs_of_album = $songs.select{|song| song.album == album_name} #array of the song with given album name
56 | songs_lengths = songs_of_album.map(&:time).sum.to_f # sum up the arrays @time of songs into 1 float
57 | song_makers = songs_of_album.map(&:artist).uniq.join(" & ").to_s #the artists
58 | #owners = songs_of_album[0].owners.split(" ") #gets owners of first song
59 |
60 | holders = songs_of_album.map(&:owners) #the owners
61 |
62 | if holders.uniq.size <= 1
63 | owners = holders
64 | else
65 | owners = []
66 | end
67 | # or array.sum { |a| a.time }
68 |
69 | Album.new(album_name, songs_of_album, songs_lengths, song_makers, holders)
70 |
71 | end
72 | end
73 |
--------------------------------------------------------------------------------
/5-iTunesTings/itunesSystem/error.rb:
--------------------------------------------------------------------------------
1 | #!/opt/local/bin/ruby2.0 -w
2 | # ERROR
3 | # Copyright Mark Keane, All Rights Reserved, 2010
4 |
5 | # Well its a class that handles errors.
6 | class MyErr
7 | attr_accessor :type, :holder, :method
8 | def initialize(type, holder, method)
9 | @type = type
10 | @holder = holder
11 | @method = method
12 | end
13 |
14 | # Method that is applied to an error object and prints out appropriate error.
15 | # Ruby actually has its own error class that you can use, when you grow up.
16 | def do_it
17 | if @type == "multiple_answer_error"
18 | then puts "Error: Item #{@holder} raised #{@type} in #{@method}"
19 | elsif @type == "not_found_error"
20 | then puts "Error: #{@holder} was #{@type} in #{@method}"
21 | else puts "Error: Have been given an unknown error type: #{@type}"
22 | end
23 | end
24 |
25 | end
--------------------------------------------------------------------------------
/5-iTunesTings/itunesSystem/itunes.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby -w
2 | # iTUNES
3 | # Copyright Mark Keane, All Rights Reserved, 2014
4 |
5 | #This is the top level
6 | require 'csv'
7 | require_relative 'actor'
8 | require_relative 'album'
9 | require_relative 'song'
10 | require_relative 'reader'
11 | require_relative 'utilities'
12 | require_relative 'error'
13 |
14 | #songs_file = ARGV[0] #for command line
15 | #owners_file = ARGV[1] #for command line
16 |
17 | reader = Reader.new
18 | songs_file = 'songs.csv' #in RubyMine
19 | owners_file = 'owners.csv' #in RubyMine
20 |
21 | puts "\nProcessing Songs from file: #{songs_file}"
22 | $songs = reader.read_in_songs(songs_file)
23 |
24 | puts "Processing Ownership from file: #{owners_file}"
25 | $hash_owners = reader.read_in_ownership(owners_file)
26 |
27 | puts "Building all owners..."
28 | $actors = Actor.build_all()
29 |
30 | puts "Updating songs with ownership details..."
31 | $songs.each{|song| song.owners = $hash_owners[song.id]}
32 |
33 | puts "Building All Albums..."
34 | $albums = Album.build_all()
35 |
36 | # Given the name of a song and a person; let them buy the song
37 | puts "\nMarkk buys The Cure..."
38 | song1 = Util.fetch("The Cure")
39 | mark = Util.fetch("markk")
40 |
41 | mark.to_s
42 | song1.to_s
43 |
44 | #album.to_s
45 | puts "printing the bought song here"
46 | mark.buys_song(song1)
47 | song1.to_s
48 |
49 | # What songs does Markk own
50 | puts "\nHow many songs does Markk own..."
51 | p mark.what_songs_does_he_own().size
52 |
53 | puts "\nPlay The Cure..."
54 | song1.play_song
55 |
56 | # Print out all songs
57 | puts "\nPrinting full details of all songs..."
58 | $songs.each{|song| p song}
59 |
60 | puts "\nPrinting full details of all Albums..."
61 | #$albums.each{|album| p album}
62 | $albums.each{|album| puts album.to_s}
63 | # Call it like this in the command line.
64 | # markkean% ruby itunes.rb songs.csv owners.csv
65 |
66 |
--------------------------------------------------------------------------------
/5-iTunesTings/itunesSystem/owners.csv:
--------------------------------------------------------------------------------
1 | "Songid","Libraries"
2 | # THIS FILE CONTAINS Mapping from Song-Ids to Owners
3 | # Aug 30 2014
4 | ######################################################
5 | # All SONGS
6 | #######################################################
7 | 10,"apple markk stinkypig"
8 | 11,"apple markk stinkypig"
9 | 12,"apple markk stinkypig"
10 | 13,"apple markk"
11 | 14,"apple markk"
12 | 15,"apple markk"
13 | 16,"apple markk"
14 | 17,"apple markk"
15 | 18,"apple markk stinkypig"
16 | 19,"apple"
17 | 20,"apple"
18 | 21,"apple"
19 | 22,"apple"
20 | 23,"apple"
21 | 24,"apple"
22 |
--------------------------------------------------------------------------------
/5-iTunesTings/itunesSystem/reader.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby -w
2 | # READER
3 | # Copyright Mark Keane, All Rights Reserved, 2014
4 |
5 | # Class that reads in things from different files.
6 | class Reader
7 | # method to read in songs from the songs.csv file.
8 | # returns an array of song objects.
9 | def read_in_songs(csv_file_name)
10 | songs = []
11 | CSV.foreach(csv_file_name, :headers => true) do |row|
12 | songname, artist, album, time, id = row[0],row[1], row[2], row[3], row[4]
13 | unless (songname =~ /#/)
14 | songs << Song.new(songname,album,artist,time.to_f,nil,id)
15 | end
16 | end
17 | songs
18 | end
19 |
20 | # method to read in owners and the ids of the songs they own from the owners.csv file.
21 | # returns a hash table where the keys are song-ids and the values are the owners this song (a string)
22 |
23 | def read_in_ownership(csv_file_name, temp_hash = Hash.new)
24 | CSV.foreach(csv_file_name, :headers => true) do |row|
25 |
26 | song_id, owner_data = row[0], row[1]
27 | unless (song_id =~ /#/)
28 | temp_hash[song_id] = owner_data
29 | end
30 | end
31 | temp_hash
32 | end
33 |
34 | end
35 |
--------------------------------------------------------------------------------
/5-iTunesTings/itunesSystem/song.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby -w
2 | # SONG
3 | # Copyright Mark Keane, All Rights Reserved, 2014
4 |
5 |
6 | # Class that encodes details of a song.
7 | class Song
8 | attr_accessor :name, :album, :artist, :time, :owners, :id
9 | def initialize(name, album, artist, time, owners, id)
10 | @name = name
11 | @album = album
12 | @time = time
13 | @artist = artist
14 | @owners = owners
15 | @id = id
16 | end
17 |
18 |
19 | # Method that prints out the contents of a song object nicely.
20 | def to_s
21 | puts "<< #{@name} >> by #{@artist} in their album #{@album} is owed by #{@owners} .\n"
22 | end
23 |
24 | # Method that checks if the object given to it is a song.
25 | def isa?
26 | instance_of?(Song)
27 | end
28 |
29 | # Method that plays a song (sort of ;-)
30 | def play_song
31 | no = rand(10)
32 | no.times {print "#{@name} do be do..."}
33 | puts "\n"
34 | end
35 |
36 | end
37 |
--------------------------------------------------------------------------------
/5-iTunesTings/itunesSystem/songs.csv:
--------------------------------------------------------------------------------
1 | "Songname","Artist","Album","Time","Id"
2 | # THIS FILE CONTAINS ALL SONGS IN iTunes
3 | # Aug 29 2014
4 | ######################################################
5 | # All SONGS
6 | #######################################################
7 | # (1) This file can be very sensitive to errors.
8 | # (2) note, that there is no space after a comma
9 | # (3) all entries are strings except time which is a float
10 | # (4) we need to explicitly write code to ignore the commented lines
11 | #######################################################
12 | # Plastic Beach by Gorillaz
13 | "Superfast Jellyfish","Gorillaz","Plastic Beach",2.55,190
14 | "On Melancholy Hill","Gorillaz","Plastic Beach",3.54,11
15 | "Broken","Gorillaz","Plastic Beach",3.17,12
16 | #
17 | # I Had the Blues and I Shook Them Loose by Bombay Bicycle Club
18 | "Always Like This","Bombay Bicycle Club","I Had the Blues and I Shook Them Loose",4.06,13
19 | #
20 | # Horehound by The Dead Weather
21 | "60 Feet Tall","The Dead Weather","Horehound",5.33,14
22 | "I Cut Like a Buffalo","The Dead Weather","Horehound",3.28,15
23 | "So Far From Your Weapon","The Dead Weather","Horehound",3.40,16
24 | #
25 | # Straight in No Kissing by Dirty Epics
26 | "Way Too Pretty","Dirty Epics","Straight in No Kissing",3.19,17
27 | "Pony","Dirty Epics","Straight in No Kissing",3.14,18
28 | "The Cure","Dirty Epics","Straight in No Kissing",2.96,19
29 | #
30 | # Crystal Castles by Crystal Castles a
31 | "Untrust Us","Crystal Castles","Crystal Castles",3.06,20
32 | "Air War","Crystal Castles","Crystal Castles",4.02,21
33 | #
34 | # Disco Crap by Multiple Artists
35 | "Staying Alive","The GBs","Disco Crap",3.06,22
36 | "Staying Alive","The GBs","Disco Crap",3.06,23
37 | "Bling","SalboNedam","Disco Crap",4.02,24
38 |
--------------------------------------------------------------------------------
/5-iTunesTings/itunesSystem/utilities.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby -w
2 | # UTILITIES
3 | # Copyright Mark Keane, All Rights Reserved, 2014
4 | # This is fairly crap...
5 |
6 | # This module takes a string-name of a song/actor/album and returns the structure with that name.
7 | # Otherwise, it throws errors of different kinds for not finding anything or finding two
8 | # structures with the submitted name.
9 | module Util
10 | #will fetch object give string that is its name
11 | def self.fetch(string_item, out = [])
12 | all = $songs + $actors #+ $albums
13 | found = all.select{|obj| string_item == obj.name}
14 | if found.size == 0
15 | then MyErr.new("not_found_error", string_item, "fetch").do_it
16 | elsif found.size > 1
17 | then MyErr.new("multiple_answer_error", string_item, "fetch").do_it
18 | elsif found.size == 1
19 | then found.first
20 | end
21 | end
22 | end
23 |
24 |
25 | class Array
26 | def clean_up()
27 | self.join(" ").split(" ").uniq #this could be more elegant
28 | end
29 | end
30 |
31 |
--------------------------------------------------------------------------------
/6-Mods-Inherit-n-iTsV2/ignore/RubyLect6.progs/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/furious-monkey/rubytest/6fafe0ae63cb110dac249a9d7e388343208227c0/6-Mods-Inherit-n-iTsV2/ignore/RubyLect6.progs/.DS_Store
--------------------------------------------------------------------------------
/6-Mods-Inherit-n-iTsV2/ignore/RubyLect6.progs/.idea/.name:
--------------------------------------------------------------------------------
1 | RubyLect6.progs
--------------------------------------------------------------------------------
/6-Mods-Inherit-n-iTsV2/ignore/RubyLect6.progs/.idea/RubyLect6.progs.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/6-Mods-Inherit-n-iTsV2/ignore/RubyLect6.progs/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/6-Mods-Inherit-n-iTsV2/ignore/RubyLect6.progs/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/6-Mods-Inherit-n-iTsV2/ignore/RubyLect6.progs/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/6-Mods-Inherit-n-iTsV2/ignore/RubyLect6.progs/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/6-Mods-Inherit-n-iTsV2/ignore/RubyLect6.progs/.idea/workspace.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 | false
268 |
269 |
270 |
271 |
272 | 1382039134842
273 | 1382039134842
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 |
290 |
291 |
292 |
293 |
294 |
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 |
324 |
325 |
326 |
327 |
328 |
329 |
330 |
331 |
332 |
333 |
334 |
335 |
336 |
337 |
338 |
339 |
340 |
341 |
342 |
343 |
344 |
345 |
346 |
347 |
348 |
349 |
350 |
351 |
352 |
353 |
354 |
355 |
356 |
357 |
358 |
359 |
360 |
361 |
362 |
363 |
364 |
365 |
--------------------------------------------------------------------------------
/6-Mods-Inherit-n-iTsV2/ignore/RubyLect6.progs/inherit.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby -w
2 | # INHERIT
3 | # Copyright Mark Keane, All Rights Reserved, 2010
4 |
5 | class Bird
6 | attr_accessor :name, :wings, :legs, :beak, :flies, :feathers
7 | def initialize(name, wings,legs,beak)
8 | @name = name
9 | @wings = wings
10 | @legs = legs
11 | @beak = beak
12 | @flies = true
13 | @feathers = true
14 | end
15 |
16 | def beak_size
17 | @beak
18 | end
19 |
20 | def can_fly?
21 | if @feathers && @flies then true
22 | elsif !@flies then false
23 | end
24 | end
25 | end
26 |
27 | class Seagull < Bird
28 | def eats_garbage?
29 | instance_of?(Seagull)
30 | end
31 |
32 | def beak_size
33 | @beak + @beak
34 | end
35 |
36 | end
37 |
38 | class Kiwi < Bird
39 | attr_accessor :cute
40 | def initialize(name, wings,legs,beak)
41 | @name = name
42 | @wings = false
43 | @legs = legs
44 | @beak = beak
45 | @flies = false
46 | @feathers = true
47 | @cute = true
48 | end
49 |
50 | def opens_shoe_polish_tins?
51 | instance_of?(Kiwi)
52 | end
53 | end
54 |
55 | jonas = Bird.new("jonas", 2, 2, "long")
56 | seagull2 = Seagull.new("henry", 2, 2, "squat")
57 | kiwi1 = Kiwi.new("kiwi", 2, 1, "long_and_thin")
58 |
59 | p jonas
60 | p seagull2
61 | p kiwi1
62 |
63 | #ruby inherit.rb
64 | #
65 | #
66 | #
83 | p seagull2.eats_garbage? # true
84 | #p kiwi1.eats_garbage? #undefined method `eats_garbage?' for #
85 |
86 | # p jonas.opens_shoe_polish_tins? undefined method `opens_shoe_polish_tins?' for #
87 | # p seagull2.opens_shoe_polish_tins? undefined method `opens_shoe_polish_tins?' for #
88 | p kiwi1.opens_shoe_polish_tins?
89 | # true
90 | puts "But, kiwis are really cute !: #{kiwi1.cute}"
--------------------------------------------------------------------------------
/6-Mods-Inherit-n-iTsV2/ignore/RubyLect6.progs/inherit_vars.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby -w
2 | # INHERIT_VARS
3 | # Copyright Mark Keane, All Rights Reserved, 2011
4 |
5 | class Bird
6 | attr_accessor :name, :wings, :legs, :beak, :flies, :batty
7 | def initialize(name, wings,legs,beak)
8 | @name = name
9 | @wings = wings
10 | @legs = legs
11 | @beak = beak
12 | @flies = true
13 | @feathers = true
14 | end
15 |
16 | end
17 |
18 | class Seagull < Bird
19 | def initialize(name, wings,legs)
20 | @namer = name
21 | @winger = wings
22 | @legser = legs
23 | end
24 | end
25 |
26 | class Kiwi < Bird
27 | :nothing
28 | end
29 |
30 | jonas = Bird.new("jonas", 2, 2, "long")
31 | seagull2 = Seagull.new("henry", 2, 2)
32 | kiwi = Kiwi.new("K", 3, 3, "very long")
33 |
34 | puts "stage 1:"
35 | p jonas
36 | p seagull2
37 |
38 | puts "stage 2:"
39 | jonas.batty = "yes"
40 | seagull2.batty = "yes"
41 | p jonas
42 | p seagull2
43 |
44 | puts "stage 3:"
45 | seagull2.flies = true
46 | p jonas
47 | p seagull2
48 | p kiwi
49 |
50 | #stage 1:
51 | #
52 | #
53 | #stage 2:
54 | #
55 | #
56 | #stage 3:
57 | #
58 | #
59 | #
--------------------------------------------------------------------------------
/6-Mods-Inherit-n-iTsV2/ignore/RubyLect6.progs/logik.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby -w
2 | # LogiK
3 | # Copyright Mark Keane, All Rights Reserved, 2010
4 |
5 | def charades(att1, att2, att3)
6 | if att1 == "green" && att2 == "tall" && att3 == "woody"
7 | then puts "Is it a tree?"
8 | elsif att1 == "green" && att2 == "tall" && !(att3 == "woody")
9 | then puts "Is it a big green thing?"
10 | elsif (att1 == "green" || att1 == "red") && (att2 == "tall")
11 | then puts "Is it a traffic light?"
12 | elsif att1 == "green" || att2 == "tall" || att3 == "woody"
13 | then puts "Is it a plant?"
14 | else puts "Haven't a clue..."
15 | end
16 | end
17 |
18 | def wh_charades(att1, att2, att3)
19 | case
20 | when att1 == "green" && att2 == "tall" && att3 == "woody"
21 | puts "Is it a tree?"
22 | when att1 == "green" && att2 == "tall" && !(att3 == "woody")
23 | puts "Is it a big green thing?"
24 | when (att1 == "green" || att1 == "red") && (att2 == "tall")
25 | puts "Is it a traffic light?"
26 | when att1 == "green" || att2 == "tall" || att3 == "woody"
27 | puts "Is it a plant?"
28 | else puts "Haven't a clue..."
29 | end
30 | end
31 |
32 |
33 | def unlesso(test)
34 | unless test
35 | puts "ok"
36 | else puts "yuk"
37 | end
38 | end
39 |
40 | puts "Unless test..."
41 | puts unlesso(true)
42 | puts unlesso(false)
43 | foo = "anything"
44 | puts unlesso(foo)
45 | puts unlesso(!foo)
46 | # Unless test
47 | # yuk
48 | # nil
49 | # ok
50 | # nil
51 | # yuk
52 | # nil
53 | # ok
54 | # nil
55 |
56 |
57 |
58 | puts "Running charades..."
59 | p charades("green","tall","woody")
60 | p charades("green","round","plastiky")
61 | p charades("red","round","woody")
62 | p charades("green","tall","stoney")
63 | p charades("red","tall","stoney")
64 | p charades("red","small","stoney")
65 | p charades("red","small","woody")
66 |
67 | # Running charades...
68 | # Is it a tree?
69 | # nil
70 | # Is it a plant?
71 | # nil
72 | # Is it a plant?
73 | # nil
74 | # Is it a big green thing?
75 | # nil
76 | # Is it a traffic light?
77 | # nil
78 | # Haven't a clue...
79 | # nil
80 | # Is it a plant?
81 | # nil
82 | puts "And Now the Wh version..."
83 | p wh_charades("green","tall","woody")
84 | p wh_charades("green","round","plastiky")
85 | p wh_charades("red","round","woody")
86 | p wh_charades("green","tall","stoney")
87 | p wh_charades("red","tall","stoney")
88 | p wh_charades("red","small","stoney")
89 | p wh_charades("red","small","woody")
90 |
91 | # And Now the Wh version...
92 | # Is it a tree?
93 | # nil
94 | # Is it a plant?
95 | # nil
96 | # Is it a plant?
97 | # nil
98 | # Is it a big green thing?
99 | # nil
100 | # Is it a traffic light?
101 | # nil
102 | # Haven't a clue...
103 | # nil
104 | # Is it a plant?
105 | # nil
106 |
107 |
--------------------------------------------------------------------------------
/6-Mods-Inherit-n-iTsV2/ignore/itunesSystem_moded.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/furious-monkey/rubytest/6fafe0ae63cb110dac249a9d7e388343208227c0/6-Mods-Inherit-n-iTsV2/ignore/itunesSystem_moded.zip
--------------------------------------------------------------------------------
/6-Mods-Inherit-n-iTsV2/itunesSystem_moded/abc/inherit.rb:
--------------------------------------------------------------------------------
1 | #this is the big daddy class
2 |
3 | class MoreOriginalA
4 | attr_accessor :looks, :vibe, :name, :age, :charisma
5 |
6 | def initialize(n)
7 | self.name = n
8 | end
9 |
10 | def vibing?
11 | "#{self.name}: yes, always"
12 | end
13 |
14 | def hi_iam
15 | "I am A"
16 | end
17 |
18 | end
19 |
20 | # this is beta daddy class
21 | class MoreOriginalB < MoreOriginalA
22 | def initialize(n, charisma)
23 | super(n)
24 | @charisma = charisma
25 | end
26 |
27 | def vibing?
28 | "#{self.name}: no, sometimes I do be vibin doe"
29 | end
30 |
31 | def hi_iam
32 | super + " nah I wish, I am B really. With #{self.charisma}"
33 | end
34 |
35 | end
36 |
37 | class MoreOriginalC < MoreOriginalB
38 |
39 | def initialize(looks)
40 | @looks = looks
41 | end
42 |
43 | def vibing?
44 | super
45 | end
46 |
47 | def hi_iam
48 | @charisma = 200;
49 | super + " but with #{self.charisma} Charisma and #{self.looks} looks"
50 | end
51 | end
52 |
53 | def print_exception(exception, explicit)
54 | puts "ERRRORRR: SOZ I cant"
55 | puts "[#{explicit ? 'EXPLICIT' : 'INEXPLICIT'}] #{exception.class}: #{exception.message}"
56 | puts exception.backtrace.join("\n")
57 | end
58 |
59 |
60 | A = MoreOriginalA.new("coolio")
61 | B = MoreOriginalB.new("lameo", -200)
62 | C = MoreOriginalC.new("cutio")
63 |
64 | puts " =====A======"
65 | puts A.vibing?
66 | puts A.hi_iam
67 | puts " =====B======"
68 | puts B.vibing?
69 | puts B.hi_iam
70 | puts " =====C======"
71 | puts C.vibing?
72 | puts C.hi_iam
73 |
74 | puts " ====test===="
75 | # A cant have charisma set up like B since it doesnt inhert anything from it
76 | begin
77 |
78 | Atest = MoreOriginalA.new("coolio", 300)
79 | puts Atest.hi_iam
80 | rescue ArgumentError => e
81 | print_exception(e, true)
82 | rescue => e
83 | print_exception(e, false)
84 | end
85 |
--------------------------------------------------------------------------------
/6-Mods-Inherit-n-iTsV2/itunesSystem_moded/actor.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby -w
2 | # ACTOR
3 | # Copyright Mark Keane, All Rights Reserved, 2014
4 |
5 | # Class that encodes details of actors that own songs/albums.
6 | class Actor
7 | attr_accessor :name, :id
8 | def initialize(name)
9 | @name = name
10 | @id = name.object_id
11 | end
12 |
13 | # Method that prints out the contents of an actor object nicely.
14 | def to_s
15 | puts "Actor #{@name} has ID: #{@id}.\n"
16 | end
17 |
18 | # Class method that builds all the actor objects using names originally from owners.csv.
19 | # Recall owners.csv got read into $hash_owners, we recover all the names associated with all
20 | # the song-ids and reduce it to an array of unique owner-name strings. We then use these to build
21 | # actor obejcts using Actor.new. The method returns an array of actor-objects.
22 |
23 | def self.build_all(data, actors = [])
24 | actor_names = data.owners.values.clean_up
25 | actor_names.each {|name| actors << Actor.new(name)}
26 | actors
27 | end
28 |
29 | # Method that takes an actor and allows him/her/it to buy a song; by just adding the persons name to the song.
30 | # Obviously, this should be more complicated, like it should write something to owners.csv too.
31 |
32 | def buys_song(song)
33 | song.owners << (" " + @name)
34 | end
35 |
36 | # Method that takes an actor finds all the songs owned by the actor.
37 | # It returns a array of song objects.
38 |
39 | def what_songs_does_he_own(data)
40 | data.songs.select{|song| song.owners.include?(@name)}
41 | end
42 |
43 | end
44 |
45 |
--------------------------------------------------------------------------------
/6-Mods-Inherit-n-iTsV2/itunesSystem_moded/album.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby -w
2 | # ALBUM
3 | # Copyright Mark Keane, All Rights Reserved, 2014
4 |
5 | # Class that encodes details of an album.
6 | class Album
7 | include Pred
8 | attr_accessor :name, :tracks, :length, :artist,:owners, :id
9 | def initialize(name, tracks, length, artist, owners)
10 | @name = name
11 | @tracks = tracks
12 | @length = length
13 | @artist = artist
14 | @owners = owners
15 | @id = name.object_id
16 | end
17 |
18 | # Method that prints out the contents of an album object nicely.
19 | def to_s
20 | puts "The album #{@name} by #{@artist}. \n"
21 | end
22 |
23 |
24 | # Method makes an album object; just uses Album.new; really
25 | # just being a bit explicit and obvious.
26 |
27 | def self.make_album(name,tracks, length, artist, owners)
28 | Album.new(name, tracks, length, artist, owners)
29 | end
30 |
31 | # Class Method that builds albums from song object's contents.
32 | # It returns an array of album objects. It calls another class method that
33 | # builds a single album, given the name of that album.
34 |
35 |
36 |
37 | def self.build_all(data, albums = [])
38 | #gets one song from each album
39 | album_names = data.songs.uniq{ |song| song.album}
40 |
41 | #calls build for each album name once and appends result
42 | album_names.each do |song|
43 | albums << build_an_album_called(data, song.album)
44 | end
45 |
46 | albums
47 | end
48 |
49 | # Class method that takes an album name, it finds all the sounds that are in that album
50 | # builds up arrays of the song-names (tracks), runtimes, artist names. These all get used
51 | # to populate the various attributes of the album object.
52 |
53 | def self.build_an_album_called(data, album_name)
54 | songs_in_album = data.songs.select { |song| song.album == album_name } #selects all songs with albumn name
55 | length = songs_in_album.inject(0){|sum,e| sum + e.time } # sums the time attribut of each song in album
56 |
57 | artist = songs_in_album[0].artist #gets artist for first song in album (same for all)
58 |
59 | #gets names of all owners of album (people who own all songs in the album)
60 | owners = songs_in_album[0].owners.split(" ") #gets owners of first song
61 | songs_in_album.drop(1).each do |song| #for each song in album except the first
62 | owners = owners & song.owners.split(" ") #gets the intersection of the owners of the current song and all previous songs
63 | end
64 |
65 |
66 | Album.make_album(album_name, songs_in_album, length , artist, owners)
67 | end
68 |
69 | end
70 |
71 |
72 |
--------------------------------------------------------------------------------
/6-Mods-Inherit-n-iTsV2/itunesSystem_moded/data.rb:
--------------------------------------------------------------------------------
1 | class DataBit
2 | attr_accessor :songs, :albums, :actors, :owners
3 | def initialize()
4 | @songs = []
5 | @albums = []
6 | @actors = []
7 | @owners = Hash.new
8 | end
9 | def songs=(x)
10 | @songs = x
11 | end
12 | def albums=(x)
13 | @albums = x
14 | end
15 | def actors=(x)
16 | @actors = x
17 | end
18 | def owners=(x)
19 | @owners = x
20 | end
21 | end
22 |
--------------------------------------------------------------------------------
/6-Mods-Inherit-n-iTsV2/itunesSystem_moded/error.rb:
--------------------------------------------------------------------------------
1 | #!/opt/local/bin/ruby2.0 -w
2 | # ERROR
3 | # Copyright Mark Keane, All Rights Reserved, 2010
4 |
5 | # Well its a class that handles errors.
6 | class MyErr
7 | attr_accessor :type, :holder, :method
8 | def initialize(type, holder, method)
9 | @type = type
10 | @holder = holder
11 | @method = method
12 | end
13 |
14 | # Method that is applied to an error object and prints out appropriate error.
15 | # Ruby actually has its own error class that you can use, when you grow up.
16 | def do_it
17 | if @type == "multiple_answer_error"
18 | then puts "Error: Item #{@holder} raised #{@type} in #{@method}"
19 | elsif @type == "not_found_error"
20 | then puts "Error: #{@holder} was #{@type} in #{@method}"
21 | else puts "Error: Have been given an unknown error type: #{@type}"
22 | end
23 | end
24 |
25 | end
--------------------------------------------------------------------------------
/6-Mods-Inherit-n-iTsV2/itunesSystem_moded/itunes.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby -w
2 | # iTUNES
3 | # Copyright Mark Keane, All Rights Reserved, 2014
4 |
5 | #This is the top level
6 | require 'csv'
7 | require_relative 'predicate'
8 | require_relative 'actor'
9 | require_relative 'album'
10 | require_relative 'song'
11 | require_relative 'reader'
12 | require_relative 'utilities'
13 | require_relative 'error'
14 | require_relative 'data'
15 |
16 |
17 | #songs_file = ARGV[0] #for command line
18 | #owners_file = ARGV[1] #for command line
19 |
20 | reader = Reader.new
21 | data = DataBit.new
22 |
23 | songs_file = 'songs.csv' #in RubyMine
24 | owners_file = 'owners.csv' #in RubyMine
25 |
26 | puts "\nProcessing Songs from file: #{songs_file}"
27 | data.songs = reader.read_in_songs(songs_file)
28 |
29 | puts "Processing Ownership from file: #{owners_file}"
30 | data.owners = reader.read_in_ownership(owners_file)
31 |
32 | puts "Building all owners..."
33 | data.actors = Actor.build_all(data)
34 |
35 | # added from previous lab ... it has gotten busy....
36 | # # handles error when an id is not in both owners csv and songs by removing song.
37 |
38 | puts "Updating songs with ownership details..."
39 | data.songs.each{|song|
40 | if song.id_match?(data.owners) then
41 | song.owners = data.owners[song.id]
42 | else
43 | song.owners = ""
44 | end
45 | }
46 | puts "Building All Albums..."
47 | data.albums = Album.build_all(data)
48 |
49 | # Given the name of a song and a person; let them buy the song
50 | puts "\nHassanA buys Break & Enter by the Prodigy..."
51 | song1 = Util.fetch(data,"Break & Enter")
52 | hassan = Util.fetch(data,"hassanA")
53 | # What songs does hassan own
54 | puts "\nHow many songs does Hassan own..."
55 | p hassan.what_songs_does_he_own(data).size
56 | hassan.to_s
57 | song1.to_s
58 | hassan.buys_song(song1)
59 | song1.to_s
60 |
61 | # What songs does Markk own
62 | puts "\nHow many songs does Hassan own..."
63 | p hassan.what_songs_does_he_own(data).size
64 |
65 | puts "\nPlay Break & Enter..."
66 | song1.play_song
67 |
68 | # Print out all songs
69 | puts "\nPrinting full details of all songs..."
70 | data.songs.each{|song| p song}
71 |
72 | puts "\nPrinting full details of all Albums..."
73 | data.albums.each{|album| p album}
74 | # Call it like this in the command line.
75 | # markkean% ruby itunes.rb songs.csv owners.csv
76 |
77 |
78 |
--------------------------------------------------------------------------------
/6-Mods-Inherit-n-iTsV2/itunesSystem_moded/owners.csv:
--------------------------------------------------------------------------------
1 | "Songid","Libraries"
2 | # THIS FILE CONTAINS Mapping from Song-Ids to Owners
3 | # Aug 30 2014
4 | ######################################################
5 | # All SONGS
6 | #######################################################
7 | 10,"apple hassanA JhonDoe"
8 | 11,"apple hassanA JhonDoe"
9 | 12,"apple hassanA JhonDoe"
10 | 13,"apple hassanA"
11 | 14,"apple hassanA"
12 | 15,"apple hassanA"
13 | 16,"apple hassanA"
14 | 17,"apple hassanA"
15 | 18,"apple hassanA JohnDoe"
16 | 19,"apple"
17 | 20,"apple"
18 | 21,"apple"
19 | 22,"apple"
20 | 23,"apple"
21 | 24,"apple"
22 |
--------------------------------------------------------------------------------
/6-Mods-Inherit-n-iTsV2/itunesSystem_moded/predicate.rb:
--------------------------------------------------------------------------------
1 | module Pred
2 | def isa?(target_class)
3 | instance_of?(target_class)
4 | end
5 | end
--------------------------------------------------------------------------------
/6-Mods-Inherit-n-iTsV2/itunesSystem_moded/reader.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby -w
2 | # READER
3 | # Copyright Mark Keane, All Rights Reserved, 2014
4 |
5 | # Class that reads in things from different files.
6 | class Reader
7 | # method to read in songs from the songs.csv file.
8 | # returns an array of song objects.
9 |
10 | def read_in_songs(csv_file_name)
11 | songs = []
12 | CSV.foreach(csv_file_name, :headers => true) do |row|
13 | songname, artist, album, time, id = row[0],row[1], row[2], row[3], row[4]
14 | unless (songname =~ /#/)
15 | songs << Song.new(songname,album,artist,time.to_f,nil,id)
16 | end
17 | end
18 | songs
19 | end
20 |
21 | # method to read in owners and the ids of the songs they own from the owners.csv file.
22 | # returns a hash table where the keys are song-ids and the values are the owners this song (a string)
23 |
24 | def read_in_ownership(csv_file_name, temp_hash = Hash.new)
25 | CSV.foreach(csv_file_name, :headers => true) do |row|
26 | song_id, owner_data = row[0], row[1]
27 | unless (song_id =~ /#/)
28 | temp_hash[song_id] = owner_data
29 | end
30 | end
31 | temp_hash
32 | end
33 | end
34 |
--------------------------------------------------------------------------------
/6-Mods-Inherit-n-iTsV2/itunesSystem_moded/song.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby -w
2 | # SONG
3 | # Copyright Mark Keane, All Rights Reserved, 2014
4 | require_relative 'data'
5 | require_relative 'predicate'
6 | # Class that encodes details of a song.
7 | class Song
8 | include Pred
9 | attr_accessor :name, :album, :artist, :time, :owners, :id
10 | def initialize(name, album, artist, time, owners, id)
11 | @name = name
12 | @album = album
13 | @time = time
14 | @artist = artist
15 | @owners = owners
16 | @id = id
17 | end
18 |
19 | #method to check if song and owner's song id match
20 | def id_match?(owners)
21 |
22 | if owners.has_key?(self.id) then
23 | true
24 | else
25 | puts "Song ID:#{self.id}, Name:'#{self.name}' does not have any owners."
26 | false
27 | end
28 | end
29 | def to_s
30 | puts "<< #{@name} >> by #{@artist} in their album #{@album} is owed by #{@owners} .\n"
31 | end
32 |
33 | def play_song
34 | no = rand(10)
35 | no.times {print "#{@name} do be do..."}
36 | puts "\n"
37 | end
38 | end
39 |
--------------------------------------------------------------------------------
/6-Mods-Inherit-n-iTsV2/itunesSystem_moded/songs.csv:
--------------------------------------------------------------------------------
1 | "Songname","Artist","Album","Time","Id"
2 | # THIS FILE CONTAINS ALL SONGS IN iTunes
3 | # Aug 29 2014
4 | ######################################################
5 | # All SONGS
6 | #######################################################
7 | # (1) This file can be very sensitive to errors.
8 | # (2) note, that there is no space after a comma
9 | # (3) all entries are strings except time which is a float
10 | # (4) we need to explicitly write code to ignore the commented lines
11 | #######################################################
12 | # Music by the Jilted Gen, by the Prodigy
13 | "Their Law","The Prodigy","Music For The Jilted Generation",4.41,10
14 | "Break & Enter","The Prodigy","Music For The Jilted Generation",4.03,111
15 | "Full Throttle","The Prodigy","Music For The Jilted Generation",3.17,12
16 | #
17 | # Blood on the Tracks by Bob Dylan
18 | "Buckets of Rain","Bob Dylan","Blood on the Tracks",4.06,13
19 | #
20 | # Everybody in ShowBiz by the Kinks
21 | "Supersonic Rocket Ship","The Kinks","Everybody in Show-biz",3.31,14
22 | "Sophisticated Lady","The Kinks","Everybody in Show-biz",3.28,15
23 | "You Don't Know My Name","The Kinks","Everybody in Show-biz",3.40,16
24 | #
25 | # The Anthology by A Tribe Called Quest
26 | "Electric Relaxation","A Tribe Called Quest","The Anthology",3.19,17
27 | #
28 | # The Wombats, Beautiful People Will Ruin Your Life
29 | "Black Flamingo","The Wombats","Beautiful People Will Ruin Your Life",3.06,20
30 | "Out of My Head","The Wombats","Beautiful People Will Ruin Your Life",4.02,21
31 | #
32 |
33 |
--------------------------------------------------------------------------------
/6-Mods-Inherit-n-iTsV2/itunesSystem_moded/txt.txt:
--------------------------------------------------------------------------------
1 | sorry late submission got busy... tryna catch up. :))
2 |
--------------------------------------------------------------------------------
/6-Mods-Inherit-n-iTsV2/itunesSystem_moded/utilities.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby -w
2 | # UTILITIES
3 | # Copyright Mark Keane, All Rights Reserved, 2014
4 | # This is fairly crap...
5 |
6 | # This module takes a string-name of a song/actor/album and returns the structure with that name.
7 | # Otherwise, it throws errors of different kinds for not finding anything or finding two
8 | # structures with the submitted name.
9 | module Util
10 | #will fetch object give string that is its name
11 | def self.fetch(data, string_item, out = [])
12 | all = data.songs + data.actors + data.albums
13 | found = all.select{|obj| string_item == obj.name}
14 | if found.size == 0
15 | then MyErr.new("not_found_error", string_item, "fetch").do_it
16 | elsif found.size > 1
17 | then MyErr.new("multiple_answer_error", string_item, "fetch").do_it
18 | elsif found.size == 1
19 | then found.first
20 | end
21 | end
22 | end
23 |
24 |
25 | class Array
26 | def clean_up()
27 | self.join(" ").split(" ").uniq #this could be more elegant
28 | end
29 | end
30 |
31 |
--------------------------------------------------------------------------------
/7-equa-mod-n-webStuff/docNoko.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby
2 |
3 | require 'nokogiri'
4 | require 'open-uri'
5 |
6 | # Fetch and parse HTML document
7 | doc = Nokogiri::HTML(URI.open('https://nokogiri.org/tutorials/installing_nokogiri.html'))
8 |
9 |
10 | pp doc
11 | #search for list content?
12 | #elements = doc.xpath("//ul")
13 |
14 | #def search_for_list_a(parse_a)
15 | # parse_a.search("//li").each do |td_element|
16 | # a = td_element.search("a")
17 | # if a.any?
18 | # then a.each {|list_a| puts "Found a link list decrip says #{list_a}"}
19 | # end
20 | # end
21 | #end
22 |
23 | #search_for_list_a(elements)
24 |
25 |
26 |
27 | # Search for nodes by css
28 | #doc.css('nav ul.menu li a', 'article h2').each do |link|
29 | #puts link.content
30 | #end
31 |
32 | # Search for nodes by xpath
33 | #doc.xpath('//nav//ul//li/a', '//article//h2').each do |link|
34 |
35 | #puts link.content
36 | #end
37 |
38 | # Or mix and match
39 | #doc.search('nav ul.menu li a', '//article//h2').each do |link|
40 | # puts link.content
41 | #end
42 |
43 |
--------------------------------------------------------------------------------
/7-equa-mod-n-webStuff/testNoko.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby
2 |
3 | require 'nokogiri'
4 | require 'open-uri'
5 |
6 | # Fetch and parse HTML document
7 | doc = Nokogiri::HTML(URI.open('https://nokogiri.org/tutorials/installing_nokogiri.html'))
8 |
9 | # Search for nodes by css
10 | doc.css('nav ul.menu li a', 'article h2').each do |link|
11 | puts link.content
12 | end
13 |
14 | # Search for nodes by xpath
15 | doc.xpath('//nav//ul//li/a', '//article//h2').each do |link|
16 | puts link.content
17 | end
18 |
19 | # Or mix and match
20 | doc.search('nav ul.menu li a', '//article//h2').each do |link|
21 | puts link.content
22 | end
23 |
24 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # exploring-ruby
2 |
3 | Exploring during a college module, to revisit and practice OOP principles and building small things with it.
4 |
--------------------------------------------------------------------------------