This repository was archived by the owner on Aug 2, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +34
-19
lines changed Expand file tree Collapse file tree 3 files changed +34
-19
lines changed Original file line number Diff line number Diff line change 1
1
# Ruby-Scripts
2
2
3
3
## Installation
4
- Download folder as zip
4
+ Download folder as zip
5
5
``` bash
6
6
gem install rest-client
7
7
```
@@ -26,4 +26,4 @@ ruby stocks.rb
26
26
## Movie Search - Uses OMDB API to return movie data
27
27
Update => OMBD API is now private, and requires an API key for use
28
28
29
- ![ ] ( https ://media.giphy .com/media/xUPGcxoW2iL5y3R4c0/giphy.gif )
29
+ ![ Imgur ] ( http ://i.imgur .com/3qTNcNY.png )
Original file line number Diff line number Diff line change 3
3
4
4
require 'Rest-Client'
5
5
require 'json'
6
+ require 'word_wrap'
6
7
7
- def movie_search ( )
8
- print "Enter a movie title -> "
8
+ # Word wrapping method
9
+ def wrap ( s , width = 78 )
10
+ s . gsub ( /(.{1,#{ width } })(\s +|\Z )/ , "\\ 1\n | " )
11
+ end
12
+
13
+ def movie_search
14
+
15
+ api_key = "1234567"
16
+
17
+ print "Movie => "
9
18
movie_name = gets . chomp
10
- url = "http://www.omdbapi.com/?t=#{ movie_name } "
19
+ url = "http://www.omdbapi.com/?t=#{ movie_name } &apikey= #{ api_key } "
11
20
response = RestClient . get ( url )
12
21
info = JSON . parse ( response )
13
22
14
23
title = info [ "Title" ]
15
24
year = info [ "Year" ]
16
- score = info [ "Metascore " ]
25
+ score = info [ "Ratings" ] [ 1 ] [ "Value "]
17
26
rated = info [ "Rated" ]
18
27
genre = info [ "Genre" ]
19
28
director = info [ "Director" ]
20
- actors = info [ "Actors" ]
21
- plot = info [ "Plot" ]
22
-
23
- puts "Title: #{ title } "
24
- puts "Year: #{ year } "
25
- puts "Metascore: #{ score } "
26
- puts "Rated: #{ rated } "
27
- puts "Genre: #{ genre } "
28
- puts "Director: #{ director } "
29
- puts "Actors: #{ actors } "
30
- puts "Plot: #{ plot } "
31
- end
29
+ actors = wrap ( info [ "Actors" ] , 48 )
30
+ plot_unformatted = info [ "Plot" ]
31
+
32
+ plot = wrap ( plot_unformatted , 48 )
32
33
33
- movie_search ( )
34
+ puts ""
35
+ puts "=================================================="
36
+ puts "| Title: #{ title } "
37
+ puts "| Year: #{ year } "
38
+ puts "| Tomato: #{ score } "
39
+ puts "| Rated: #{ rated } "
40
+ puts "| Genre: #{ genre } "
41
+ puts "| Director: #{ director } "
42
+ puts "| Actors: #{ actors } "
43
+ puts "| Plot: #{ plot } "
44
+ puts "=================================================="
45
+ puts ""
46
+ end
34
47
48
+ movie_search
Original file line number Diff line number Diff line change 5
5
require 'json'
6
6
7
7
def stock_search
8
+
8
9
# Cptures user inputs
9
10
puts ""
10
11
print "Stock => "
You can’t perform that action at this time.
0 commit comments