├── README.md
└── ex00
└── my_select_query.rb
/README.md:
--------------------------------------------------------------------------------
1 | # Welcome to My Select Query
2 | ***
3 |
4 | ## Task
5 | For each exercise, you will have to create a folder and in this folder,
6 | you will have additional files that contain your work.
7 | Implement a where method which will take 2 arguments: column_name and value.
8 | It will return an array of strings which matches the value.
9 |
10 | ## Description
11 | Your constructor will receive a CSV content (as a string), first line will be the name of the column.
12 | For each exercise, you will have to create a folder and in this folder
13 |
14 | ## Installation
15 | not installed
16 |
17 | ## Usage
18 | TODO - How does it work?
19 | ```
20 | ./my_project argument1 argument2
21 | ```
22 |
23 | ### The Core Team
24 |
25 |
26 | Made at Qwasar Silicon Valley
27 |
28 |
--------------------------------------------------------------------------------
/ex00/my_select_query.rb:
--------------------------------------------------------------------------------
1 | require 'csv'
2 |
3 | class MySelectQuery
4 | def initialize(content)
5 | @data = CSV.parse(content, headers: true)
6 | end
7 |
8 | def where(columns, values)
9 | results = []
10 | @data.filter do |row|
11 | if row[columns] == values
12 | results << row.to_hash.values.join(",")
13 | end
14 | end
15 | results
16 | end
17 | end
18 |
19 | # def main
20 | # content = "name,year_start,year_end,position,height,weight,birth_date,college\nAlaa Abdelnaby,1991,1995,F-C,6-10,240,'June 24, 1968',Duke University\nZaid Abdul-Aziz,1969,1978,C-F,6-9,235,'April 7, 1946',Iowa State University\nKareem Abdul-Jabbar,1970,1989,C,7-2,225,'April 16, 1947','University of California, Los Angeles
21 | # Mahmoud Abdul-Rauf,1991,2001,G,6-1,162,'March 9, 1969',Louisiana State University\n"
22 | # query = MySelectQuery.new(content)
23 | # puts query.where("name", "Kareem Abdul-Jabbar")
24 | # end
25 |
26 | # main()
--------------------------------------------------------------------------------