berklee-valencia 0.1.5 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: abfec51df5da1d9aef8c1e8bbd0b86f1d9c454c93ad8854b4b198ae47539621f
4
- data.tar.gz: 72b1672acf9911addaf3ee623a574aded2ff07a5fab944ef6d51806b4bd78b40
3
+ metadata.gz: 8f285d72b0611c1f7668b8c7e0280fd614c38409dea17fe4dfa683fe6910d27e
4
+ data.tar.gz: 933831281bdb32e0382c6dff11834af2ee39c68170fc23283f5aa0ae5e8a2748
5
5
  SHA512:
6
- metadata.gz: cee38cc3dc32f75262aa391a4ed568a7bdc47014992cb1740dc95f1b70ca5ae30adb93106beefd39084c81fc9ac59777c12aeac02bfce42359eac53adbf295b4
7
- data.tar.gz: a34fe3de07687a0754e96e477182647a8d3b42e7e6fc524d155cafaa581b5d40892a65533058be5c77830a340f52246c4788cf9009635d51adc6bc0ce1e36de9
6
+ metadata.gz: a6265963d483e171c9825adc4ac76934b5c6d0e7ae32925c187353482050a7b305c06fac20418995de72903d2fa1fdc20871881d2b60aceeed48fb477443fec4
7
+ data.tar.gz: e60d265bb275b9d37743d5257ebc58c56f774fd7ab1fb4e3952750cb1e21f7e694f67cb220f169ef22dba4d24ffe16933fca18a3f5837bd186fae1a414d45206
@@ -2,7 +2,9 @@
2
2
  #
3
3
  require_relative '../lib/berklee_valencia.rb'
4
4
  #
5
- BerkleeValencia::CLI.new.call
5
+ # BerkleeValencia::CLI.new.call
6
+ session = BerkleeValencia::CLI.new.call
7
+
6
8
 
7
9
 
8
10
  # ||
@@ -1,13 +1,23 @@
1
1
  require 'nokogiri'
2
2
  require 'open-uri'
3
3
  require "open_uri_redirections"
4
+ #
5
+ # require_relative "../lib/berklee_valencia/version.rb"
6
+ # require_relative '../lib/berklee_valencia/cli.rb'
7
+ # require_relative '../lib/berklee_valencia/scraper.rb'
8
+ # require_relative '../lib/berklee_valencia/news_article.rb'
9
+ # require_relative '../lib/berklee_valencia/program.rb'
10
+ # require_relative '../lib/berklee_valencia/printer.rb'
11
+ # require_relative '../lib/berklee_valencia/formatter.rb'
12
+ # require_relative '../lib/berklee_valencia/printer.rb'
13
+ # require_relative '../lib/berklee_valencia/news_article.rb'
4
14
 
5
15
  require_relative "../lib/berklee_valencia/version.rb"
6
16
  require_relative '../lib/berklee_valencia/cli.rb'
7
17
  require_relative '../lib/berklee_valencia/scraper.rb'
8
- require_relative '../lib/berklee_valencia/news_article.rb'
18
+ require_relative '../lib/berklee_valencia/item.rb'
19
+ require_relative '../lib/berklee_valencia/article.rb'
9
20
  require_relative '../lib/berklee_valencia/program.rb'
21
+ require_relative '../lib/berklee_valencia/category.rb'
10
22
  require_relative '../lib/berklee_valencia/printer.rb'
11
23
  require_relative '../lib/berklee_valencia/formatter.rb'
12
- require_relative '../lib/berklee_valencia/printer.rb'
13
- require_relative '../lib/berklee_valencia/news_article.rb'
@@ -2,3 +2,4 @@ module BerkleeValencia
2
2
  end
3
3
 
4
4
  require_relative '../config/environment.rb'
5
+
@@ -0,0 +1,25 @@
1
+ class BerkleeValencia::ARTICLE < BerkleeValencia::ITEM
2
+ attr_accessor :date, :excerpt, :category, :author, :related_links, :body, :i
3
+ @@all = []
4
+
5
+ def self.new_from_scraper(attribute_hash)
6
+ BerkleeValencia::ARTICLE.new(attribute_hash[:title], attribute_hash[:url]).tap do |article|
7
+ article.category = attribute_hash[:category]
8
+ article.date = attribute_hash[:date]
9
+ article.excerpt = attribute_hash[:excerpt]
10
+ @@all << article
11
+ BerkleeValencia::CATEGORY.find_or_create_from_article(article)
12
+ end
13
+ end
14
+
15
+ def extended_info_from_scraper(attribute_hash)
16
+ @author = attribute_hash[:author]
17
+ @related_links = attribute_hash[:related_links]
18
+ @body = attribute_hash[:body]
19
+ end
20
+
21
+ def self.all
22
+ @@all
23
+ end
24
+
25
+ end
@@ -0,0 +1,44 @@
1
+ class BerkleeValencia::CATEGORY
2
+ attr_accessor :title, :i, :articles
3
+
4
+ @@all = []
5
+
6
+ def initialize(title)
7
+ @title = title
8
+ @articles = []
9
+ @@all << self
10
+ end
11
+
12
+ def self.find_by_title(title)
13
+ @@all.detect {|cat| cat.title == title}
14
+ end
15
+
16
+ def self.find_or_create_from_article(article)
17
+ if find_by_title(article.category)
18
+ find_by_title(article.category).articles << article
19
+ else
20
+ self.new(article.category).tap {|cat| cat.articles << article}
21
+ end
22
+ end
23
+
24
+ def self.find_cat_by_index(input)
25
+ all.detect{|cat| cat.i == input.to_i}
26
+ end
27
+
28
+ def find_article_by_index(input)
29
+ @articles.detect{|article| article.i == input.to_i}
30
+ end
31
+
32
+ def self.index_categories
33
+ @@all.each.with_index(1) {|cat, i| cat.i = i}
34
+ end
35
+
36
+ def index_articles
37
+ @articles.each.with_index(1) {|article, i| article.i = i}
38
+ end
39
+
40
+ def self.all
41
+ @@all
42
+ end
43
+
44
+ end
@@ -1,16 +1,17 @@
1
1
  class BerkleeValencia::CLI
2
+
2
3
  def call
3
4
  puts ""
4
5
  puts "||"
5
6
  puts "||"
6
- puts "|| /|| Buenos Dias!"
7
+ puts "|| /|| Buenos Días!"
7
8
  puts "|| //||"
8
9
  puts "|| // || Berklee Valencia is Berklee College of Music's"
9
10
  puts "||// || graduate campus located in Valencia, Spain"
10
11
  puts "||/ ||"
11
12
  puts "|| || Filled with the"
12
- puts "|| /|| musicians"
13
- puts "|| //|| business moguls"
13
+ puts "|| /|| musicians,"
14
+ puts "|| //|| business moguls,"
14
15
  puts "|| // || and technologists"
15
16
  puts "||// || of today and tomorrow..."
16
17
  puts "||/ ||"
@@ -27,110 +28,120 @@ class BerkleeValencia::CLI
27
28
  puts " 1. Meet the people and read the latest news"
28
29
  puts " 2. See the available Programs"
29
30
  puts ""
30
- list_news_or_programs
31
+ programs_or_news
31
32
  end
32
33
 
33
- def list_news_or_programs
34
+ def programs_or_news
34
35
  input = gets.strip.downcase
35
36
  if input.match(/hasta luego|exit|bye|ciao/)
36
37
  goodbye
37
- else
38
- puts ""
39
- puts " Please be patient whilst we get up to date with all our news!"
40
- puts ""
41
- puts " ... ... ..."
42
- puts ""
43
- if input == "1"
44
- show_news_categories
45
- elsif input == "2"
46
- show_programs
47
- elsif input == "programs"
48
- what_next
49
- else
50
- say_what
38
+ elsif input == "1" || input == "2"
39
+ please_wait
40
+ case input
41
+ when "1"
42
+ list_article_categories
43
+ when "2"
44
+ list_programs
51
45
  end
46
+ else
47
+ say_what
52
48
  end
53
49
  end
54
50
 
55
- def list_news_articles
51
+ def list_programs
52
+ if BerkleeValencia::PROGRAM.all == []
53
+ BerkleeValencia::SCRAPER.make_programs
54
+ end
56
55
  puts ""
56
+ puts "----------------------------------------------------------------"
57
+ puts " Enter the number of the program you'd like to read more about"
58
+ puts " or type 'news' to browse our latest news and articles."
59
+ puts "----------------------------------------------------------------"
60
+ BerkleeValencia::PRINTER.print_programs_list
57
61
  input = gets.strip.downcase
58
- if input.to_i > 0
59
- puts ""
60
- puts "----------------------------------------------------------"
61
- puts "Enter the number of the article you'd like to read in full"
62
- puts " or type 'menu' to see all options"
63
- puts "----------------------------------------------------------"
64
- BerkleeValencia::NEWS_ARTICLE.list_news_articles(input)
65
- show_article
66
- elsif input == "programs"
67
- show_programs
62
+ if input.to_i.between?(1,BerkleeValencia::PROGRAM.all.length)
63
+ show_program(input)
64
+ elsif input == "news"
65
+ list_article_categories
66
+ elsif input.match(/hasta luego|exit|bye|ciao/)
67
+ goodbye
68
68
  else
69
69
  say_what
70
70
  end
71
71
  end
72
72
 
73
- def show_news_categories
74
- BerkleeValencia::NEWS_ARTICLE.get_news_categories
73
+ def show_program(input)
74
+ program = BerkleeValencia::PROGRAM.find_by_index(input.to_i)
75
+ if !program.introduction
76
+ attributes = BerkleeValencia::SCRAPER.get_program_extended_info(program.url)
77
+ program.extended_info_from_scraper(attributes)
78
+ end
79
+ BerkleeValencia::PRINTER.print_program(program)
80
+ what_next
81
+ end
82
+
83
+ def list_article_categories
84
+ if BerkleeValencia::ARTICLE.all == []
85
+ BerkleeValencia::SCRAPER.make_articles
86
+ end
75
87
  puts ""
76
88
  puts "----------------------------------------------"
77
89
  puts " Which kind of article are you interested in?"
78
90
  puts " Type 'programs' to browse programs instead"
79
91
  puts "----------------------------------------------"
80
- BerkleeValencia::NEWS_ARTICLE.list_news_categories
81
- list_news_articles
82
- end
83
-
84
- def show_programs
85
- BerkleeValencia::PROGRAM.get_programs
86
- puts ""
87
- puts "----------------------------------------------------------------"
88
- puts " Enter the number of the program you'd like to read more about"
89
- puts " or type 'news' to browse our latest news and articles."
90
- puts "----------------------------------------------------------------"
91
- puts "Graduate Programs"
92
- BerkleeValencia::PROGRAM.list_programs("grad")
93
- puts ""
94
- puts "Other Programs"
95
- BerkleeValencia::PROGRAM.list_programs("other")
96
- show_program
97
- end
98
-
99
- def show_article
100
- puts ""
92
+ BerkleeValencia::CATEGORY.index_categories
93
+ BerkleeValencia::PRINTER.print_article_categories
101
94
  input = gets.strip.downcase
102
- if input.to_i > 0
103
- if BerkleeValencia::NEWS_ARTICLE.print_article(input) == "abort mission!"
104
- menu
105
- else
106
- what_next
107
- end
108
- elsif input == "menu"
109
- what_next
95
+ if input.to_i.between?(1,BerkleeValencia::CATEGORY.all.length)
96
+ list_articles(input)
97
+ elsif input == "programs"
98
+ list_programs
99
+ elsif input.match(/hasta luego|exit|bye|ciao/)
100
+ goodbye
110
101
  else
111
102
  say_what
112
103
  end
113
104
  end
114
105
 
115
- def show_program
106
+ def list_articles(input)
116
107
  puts ""
108
+ puts "----------------------------------------------------------"
109
+ puts "Enter the number of the article you'd like to read in full"
110
+ puts " or type 'menu' to see all options"
111
+ puts "----------------------------------------------------------"
112
+ category = BerkleeValencia::CATEGORY.find_cat_by_index(input)
113
+ category.index_articles
114
+ BerkleeValencia::PRINTER.print_articles_list(category)
117
115
  input = gets.strip.downcase
118
- if input.to_i > 0
119
- BerkleeValencia::PROGRAM.print_program(input)
120
- what_next
121
- elsif input == "news"
122
- show_news_categories
116
+ if input.to_i.between?(1,category.articles.length)
117
+ show_article(category, input)
118
+ elsif input == "menu"
119
+ programs_or_news
120
+ elsif input.match(/hasta luego|exit|bye|ciao/)
121
+ goodbye
123
122
  else
124
123
  say_what
125
124
  end
126
125
  end
127
126
 
128
- def say_what
129
- puts ""
130
- puts "Sorry, I didn't understand that!"
127
+ def show_article(category, input)
128
+ article = category.find_article_by_index(input)
129
+ if !article.body
130
+ attributes = BerkleeValencia::SCRAPER.get_article_extended_info(article.url)
131
+ article.extended_info_from_scraper(attributes)
132
+ end
133
+ BerkleeValencia::PRINTER.print_article(article)
131
134
  what_next
132
135
  end
133
136
 
137
+ def please_wait
138
+ puts ""
139
+ puts " Please be patient whilst we get up to date with all our news!"
140
+ puts ""
141
+ puts " ... ... ..."
142
+ puts ""
143
+ end
144
+
134
145
  def what_next
135
146
  puts ""
136
147
  puts "What would you like to do next?"
@@ -140,13 +151,20 @@ class BerkleeValencia::CLI
140
151
  puts " If you're all set, you can just say ciao for now and we will "
141
152
  puts " see you next time with the latest news from Berklee Valencia!"
142
153
  puts ""
143
- list_news_or_programs
154
+ programs_or_news
144
155
  end
145
156
 
157
+ def say_what
158
+ puts ""
159
+ puts "Sorry, I didn't understand that!"
160
+ what_next
161
+ end
146
162
 
147
163
  def goodbye
148
164
  puts ""
149
165
  puts "Hasta luego!"
150
166
  puts ""
167
+ exit!
151
168
  end
169
+
152
170
  end
@@ -4,43 +4,43 @@ class Formatter
4
4
  text.gsub(/(.{1,#{width}})(\s+|\Z)/, "\\1\n")
5
5
  end
6
6
 
7
- class Article < Formatter
8
- def self.header(article, article_extended)
9
- border = border_maker(article, article_extended)
7
+ class Formatter::FORMATARTICLE < Formatter
8
+ def self.header(article)
9
+ border = border_maker(article)
10
10
  puts ""
11
11
  2.times {puts "#{border}"}
12
- puts "#{wrap(article[:title])}"
13
- gap = gap_maker(article, article_extended, border)
14
- puts "#{article_extended[:author]}#{gap}#{article[:date]}"
12
+ puts "#{wrap(article.title)}"
13
+ gap = gap_maker(article, border)
14
+ puts "#{article.author}#{gap}#{article.date}"
15
15
  2.times {puts "#{border}"}
16
16
  end
17
17
 
18
- def self.border_maker(article, article_extended)
18
+ def self.border_maker(article)
19
19
  border = ""
20
- if article[:title].length < (article_extended[:author].length + article[:date].length)
21
- borderlength = article_extended[:author].length + article[:date].length + 5
20
+ if article.title.length < (article.author.length + article.date.length)
21
+ borderlength = article.author.length + article.date.length + 5
22
22
  borderlength.times {border << "-"}
23
- elsif article[:title].length > 80
23
+ elsif article.title.length > 80
24
24
  80.times {border << "-"}
25
25
  else
26
- borderlength = article[:title].length
26
+ borderlength = article.title.length
27
27
  borderlength.times {border << "-"}
28
28
  end
29
29
  border
30
30
  end
31
31
 
32
- def self.gap_maker(article, article_extended, border)
32
+ def self.gap_maker(article, border)
33
33
  gap = ""
34
- if border.length > article[:title].length
34
+ if border.length > article.title.length
35
35
  5.times {gap << " "}
36
36
  else
37
- (article[:title].length - article_extended[:author].length - article[:date].length).times {gap << " "}
37
+ (article.title.length - article.author.length - article.date.length).times {gap << " "}
38
38
  end
39
39
  gap
40
40
  end
41
41
 
42
- def self.body(article, article_extended)
43
- article_extended[:body].each do |paragraph|
42
+ def self.body(article)
43
+ article.body.each do |paragraph|
44
44
  if paragraph.match(/-{3} /)
45
45
  puts " ______________________________________________________________________________"
46
46
  puts " || Press enter to scroll to the next section ||"
@@ -48,16 +48,14 @@ class Formatter
48
48
  puts " ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾"
49
49
  input = gets.strip
50
50
  if input == "menu"
51
- return "abort mission!"
51
+ return "menu"
52
52
  end
53
- end
54
-
55
- if !paragraph.downcase.match(/click here/)
53
+ elsif !paragraph.downcase.match(/click here/)
56
54
  if paragraph.match(/below/)
57
55
  puts "#{wrap(paragraph)}"
58
- puts " Vist #{article_extended[:related_links].shift}"
56
+ puts " Vist #{article.related_links.shift}"
59
57
  elsif paragraph == " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
60
- puts " Vist #{article_extended[:related_links].shift}"
58
+ puts " Vist #{article.related_links.shift}"
61
59
  puts paragraph
62
60
  else
63
61
  puts "#{wrap(paragraph)}"
@@ -74,33 +72,31 @@ class Formatter
74
72
  puts " ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾"
75
73
  2.times {puts ""}
76
74
  end
77
- end
75
+ end #class
78
76
 
79
- class Program < Formatter
77
+ class Formatter::FORMATPROGRAM < Formatter
80
78
  def self.header(program)
81
79
  border = ""
82
- (program[:name].gsub("#{program[:detail]}", "").length + 4).times {border << "-"}
80
+ (program.title.length + 4).times {border << "-"}
83
81
  puts ""
84
82
  2.times {puts border}
85
- puts " #{program[:name].gsub("#{program[:detail]}", "")}"
86
- if program[:detail] != ""
87
- puts " (#{program[:detail]})"
88
- end
83
+ puts " #{program.title}"
84
+ puts " #{program.type}"
89
85
  end
90
86
 
91
- def self.intro(program_extended)
87
+ def self.intro(program)
92
88
  puts "--------------------------------------------------------------------------------"
93
89
  puts " Introduction"
94
90
  puts "--------------------------------------------------------------------------------"
95
- puts "#{wrap(program_extended[:introduction])}"
91
+ puts "#{wrap(program.introduction)}"
96
92
  puts ""
97
93
  end
98
94
 
99
- def self.highlights(program_extended)
95
+ def self.highlights(program)
100
96
  puts "--------------------------------------------------------------------------------"
101
97
  puts " Program Highlights"
102
98
  puts "--------------------------------------------------------------------------------"
103
- program_extended[:highlights].each do |highlight|
99
+ program.highlights.each do |highlight|
104
100
  puts "| #{highlight[:hl_title]} |"
105
101
  puts "#{wrap(highlight[:hl_body])}"
106
102
  puts ""
@@ -111,7 +107,7 @@ class Formatter
111
107
  puts "--------------------------------------------------------------------------------"
112
108
  puts " For full program information:"
113
109
  puts "--------------------------------------------------------------------------------"
114
- puts "Visit #{program[:url]}"
110
+ puts "Visit #{program.url}"
115
111
  2.times {puts "--------------------------------------------------------------------------------"}
116
112
  2.times {puts ""}
117
113
  end
@@ -0,0 +1,10 @@
1
+ class BerkleeValencia::ITEM
2
+ attr_reader :title, :url
3
+
4
+ def initialize(title, url)
5
+ @title = title
6
+ @url = url
7
+ end
8
+
9
+
10
+ end
@@ -1,16 +1,53 @@
1
1
  class BerkleeValencia::PRINTER
2
- def self.print_article(article, article_extended)
3
- Formatter::Article.header(article, article_extended)
4
- Formatter::Article.body(article, article_extended)
5
- Formatter::Article.end
2
+
3
+ def self.print_programs_list
4
+ puts "Graduate Programs"
5
+ BerkleeValencia::PROGRAM.graduate_programs.each do |program|
6
+ if program.subtitle.length > 0
7
+ puts "#{program.i}: #{program.title.gsub(program.subtitle, "")} (#{program.subtitle})"
8
+ else
9
+ puts "#{program.i}: #{program.title}"
10
+ end
11
+ end
12
+ puts ""
13
+ puts "Other Programs"
14
+ BerkleeValencia::PROGRAM.other_programs.each do |program|
15
+ if program.subtitle.length > 0
16
+ puts "#{program.i}: #{program.title.gsub(program.subtitle, "")} (#{program.subtitle})"
17
+ else
18
+ puts "#{program.i}: #{program.title}"
19
+ end
20
+ end
21
+ puts ""
6
22
  end
7
23
 
8
- def self.print_program(program, program_extended)
9
- Formatter::Program.header(program)
10
- Formatter::Program.intro(program_extended)
11
- if program_extended[:highlights].length > 0
12
- Formatter::Program.highlights(program_extended)
24
+ def self.print_program(program)
25
+ Formatter::FORMATPROGRAM.header(program)
26
+ Formatter::FORMATPROGRAM.intro(program)
27
+ if program.highlights.length > 0
28
+ Formatter::FORMATPROGRAM.highlights(program)
13
29
  end
14
- Formatter::Program.more_info(program)
30
+ Formatter::FORMATPROGRAM.more_info(program)
15
31
  end
16
- end #class
32
+
33
+ def self.print_article_categories
34
+ BerkleeValencia::CATEGORY.all.each {|cat| puts "#{cat.i}. #{cat.title}"}
35
+ puts ""
36
+ end
37
+
38
+ def self.print_articles_list(category)
39
+ category.articles.each do |article|
40
+ puts "#{article.i}: #{Formatter.wrap(article.title)}"
41
+ puts " // Posted on #{article.date}"
42
+ puts "#{Formatter.wrap(article.excerpt)}"
43
+ puts ""
44
+ end
45
+ end
46
+
47
+ def self.print_article(article)
48
+ Formatter::FORMATARTICLE.header(article)
49
+ Formatter::FORMATARTICLE.body(article)
50
+ Formatter::FORMATARTICLE.end
51
+ end
52
+
53
+ end
@@ -1,28 +1,37 @@
1
- class BerkleeValencia::PROGRAM
2
- @@grad_programs
3
- @@other_programs
1
+ class BerkleeValencia::PROGRAM < BerkleeValencia::ITEM
2
+ attr_accessor :type, :introduction, :subtitle, :highlights, :i
3
+ @@all = []
4
+ @@graduate_programs = []
5
+ @@other_programs = []
4
6
 
5
- def self.get_programs
6
- @@grad_programs = BerkleeValencia::SCRAPER.scrape_programs("grad")
7
- @@other_programs = BerkleeValencia::SCRAPER.scrape_programs("other")
7
+ def self.new_from_scraper(attribute_hash)
8
+ new_program = BerkleeValencia::PROGRAM.new(attribute_hash[:title], attribute_hash[:url])
9
+ new_program.type = attribute_hash[:type]
10
+ new_program.subtitle = attribute_hash[:subtitle]
11
+ new_program.i = @@all.length + 1
12
+ @@all << new_program
13
+ new_program.type == "Graduate Programs" ? @@graduate_programs << new_program : @@other_programs << new_program
8
14
  end
9
15
 
10
- def self.list_programs(type)
11
- type == "grad" ? programs = @@grad_programs : programs = @@other_programs
12
- programs == @@grad_programs ? i = 1 : i = (@@grad_programs.length + 1)
13
- programs.each.with_index(i) do |program, i|
14
- (program[:detail] != "") ? (puts "#{i}: #{program[:name].gsub("#{program[:detail]}", "")} (#{program[:detail]})") : (puts "#{i}: #{program[:name]}")
15
- program[:i] = i
16
- end# do
17
- end #list programs method
16
+ def extended_info_from_scraper(attribute_hash)
17
+ @highlights = attribute_hash[:highlights]
18
+ @introduction = attribute_hash[:introduction]
19
+ end
20
+
21
+ def self.find_by_index(input)
22
+ @@all.detect{|program| program.i == input}
23
+ end
24
+
25
+ def self.graduate_programs
26
+ @@graduate_programs
27
+ end
28
+
29
+ def self.other_programs
30
+ @@other_programs
31
+ end
18
32
 
19
- def self.print_program(input)
20
- programs = @@grad_programs
21
- @@other_programs.each { |program| programs << program }
22
- program = programs.find { |program| program[:i] == input.to_i }
23
- url = program[:url]
24
- program_extended = BerkleeValencia::SCRAPER.scrape_program(url)
25
- BerkleeValencia::PRINTER.print_program(program, program_extended)
26
- end #method
33
+ def self.all
34
+ @@all
35
+ end
27
36
 
28
- end #class
37
+ end
@@ -1,36 +1,37 @@
1
1
  class BerkleeValencia::SCRAPER
2
- @bv_news = "https://valencia.berklee.edu/news/"
3
- @bv_programs = "https://valencia.berklee.edu/academic-programs/"
2
+ @@bv_news = "https://valencia.berklee.edu/news/"
3
+ @@bv_programs = "https://valencia.berklee.edu/academic-programs/"
4
4
 
5
- def self.scrape_news
6
- news = Nokogiri::HTML(open(@bv_news))
7
- articles = []
8
- news.css("div#news_container div.content").each do |article|
9
- articles << {
10
- date: article.css("div.news_excerpt span.date").text,
11
- title: article.css("div.news_excerpt h3 a").text,
12
- excerpt: article.css("div.news_excerpt p").text,
13
- url: article.css("div.news_excerpt h3 a").attribute("href").value,
14
- category: article.css("span.category_name").text
15
- }
5
+ def self.make_programs
6
+ course_types = Nokogiri::HTML(open(@@bv_programs)).css("div.col-3-5")
7
+ course_types.each do |type|
8
+ type.css("ul a").each do |program|
9
+ attributes = {
10
+ title: program.text,
11
+ subtitle: program.css("span").text,
12
+ url: program.attribute("href").value,
13
+ type: type.css("h4").text
14
+ }
15
+ BerkleeValencia::PROGRAM.new_from_scraper(attributes)
16
+ end
16
17
  end
17
- articles
18
18
  end
19
19
 
20
- def self.scrape_programs(type)
21
- type == "grad" ? academics = Nokogiri::HTML(open(@bv_programs)).css("div.col-3-5").first : academics = Nokogiri::HTML(open(@bv_programs)).css("div.col-3-5").last
22
- programs = []
23
- academics.css("ul a").each do |program|
24
- programs << {
25
- name: program.text,
26
- detail: program.css("span").text,
27
- url: program.attribute("href").value
20
+ def self.make_articles
21
+ articles = Nokogiri::HTML(open(@@bv_news))
22
+ articles.css("div#news_container div.content").each do |article|
23
+ attributes = {
24
+ title: article.css("div.news_excerpt h3 a").text,
25
+ category: article.css("span.category_name").text,
26
+ date: article.css("div.news_excerpt span.date").text,
27
+ excerpt: article.css("div.news_excerpt p").text,
28
+ url: article.css("div.news_excerpt h3 a").attribute("href").value
28
29
  }
30
+ BerkleeValencia::ARTICLE.new_from_scraper(attributes)
29
31
  end
30
- programs
31
32
  end
32
33
 
33
- def self.scrape_article(url)
34
+ def self.get_article_extended_info(url)
34
35
  article = Nokogiri::HTML(open(url))
35
36
  extended_info = {
36
37
  author: article.css("span.author").text,
@@ -38,6 +39,18 @@ class BerkleeValencia::SCRAPER
38
39
  body: []
39
40
  }
40
41
  sort_content(article, extended_info)
42
+ extended_info
43
+ end
44
+
45
+ def self.get_program_extended_info(url)
46
+ program = Nokogiri::HTML(open(url, :allow_redirections => :all))
47
+ extended_info = {
48
+ introduction: "",
49
+ highlights: []
50
+ }
51
+ scrape_program_intro(program, extended_info)
52
+ scrape_program_highlights(program, extended_info)
53
+ extended_info
41
54
  end
42
55
 
43
56
  def self.sort_content(article, extended_info)
@@ -58,18 +71,7 @@ class BerkleeValencia::SCRAPER
58
71
  extended_info
59
72
  end
60
73
 
61
- def self.scrape_program(url)
62
- program = Nokogiri::HTML(open(url, :allow_redirections => :all))
63
- extended_info = {
64
- highlights: [],
65
- list: []
66
- }
67
- scrape_program_intro(program, extended_info)
68
- scrape_program_highlights(program, extended_info)
69
- end
70
-
71
74
  def self.scrape_program_intro(program, extended_info)
72
- # scrape intro
73
75
  if program.css("div#tab_intro p").first.text.length > 0
74
76
  extended_info[:introduction] = program.css("div#tab_intro p").first.text
75
77
  elsif program.css("div#tab_intro h4").length > 0
@@ -89,8 +91,6 @@ class BerkleeValencia::SCRAPER
89
91
  hl_body: hl_body
90
92
  }
91
93
  end
92
- extended_info
93
94
  end
94
95
 
95
-
96
- end
96
+ end #class
@@ -1,3 +1,3 @@
1
1
  module BerkleeValencia
2
- VERSION = "0.1.5"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: berklee-valencia
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gingertonic
@@ -106,9 +106,11 @@ files:
106
106
  - bin/berklee-valencia
107
107
  - config/environment.rb
108
108
  - lib/berklee_valencia.rb
109
+ - lib/berklee_valencia/article.rb
110
+ - lib/berklee_valencia/category.rb
109
111
  - lib/berklee_valencia/cli.rb
110
112
  - lib/berklee_valencia/formatter.rb
111
- - lib/berklee_valencia/news_article.rb
113
+ - lib/berklee_valencia/item.rb
112
114
  - lib/berklee_valencia/printer.rb
113
115
  - lib/berklee_valencia/program.rb
114
116
  - lib/berklee_valencia/scraper.rb
@@ -1,39 +0,0 @@
1
- class BerkleeValencia::NEWS_ARTICLE
2
- @@categories
3
- @@articles
4
- @@matches
5
-
6
- def self.get_news_categories
7
- @@articles = BerkleeValencia::SCRAPER.scrape_news
8
- @@categories = []
9
- @@articles.each do |article|
10
- @@categories.push(article[:category])
11
- end
12
- @@categories.uniq!
13
- end
14
-
15
- def self.list_news_categories
16
- @@categories.each.with_index(1) do |category, i|
17
- puts "#{i}. #{category}"
18
- end
19
- end
20
-
21
- def self.list_news_articles(input)
22
- @@matches = @@articles.find_all {|article| article[:category] == @@categories[input.to_i-1]}
23
- @@matches.each.with_index(1) do |article, i|
24
- puts "#{i}: #{Formatter.wrap(article[:title])}"
25
- puts " // Posted on #{article[:date]}"
26
- puts "#{Formatter.wrap(article[:excerpt])}"
27
- puts ""
28
- article[:i] = i
29
- end
30
- end
31
-
32
- def self.print_article(input)
33
- article = @@articles.find { |article| article[:i] == input.to_i }
34
- url = article[:url]
35
- article_extended = BerkleeValencia::SCRAPER.scrape_article(url)
36
- BerkleeValencia::PRINTER.print_article(article, article_extended)
37
- end
38
-
39
- end