Class: Blog
- Inherits:
-
Object
- Object
- Blog
- Defined in:
- lib/Blog.rb
Constant Summary collapse
- FILE =
'structured_exceptions.yml'- NO_EXCEPTIONS =
"No exceptions have been raised by files that require 'ruby_blogger'"
Instance Attribute Summary collapse
-
#count_and_files ⇒ Object
readonly
Returns the value of attribute count_and_files.
-
#count_of_exceptions_in_folder ⇒ Object
readonly
Returns the value of attribute count_of_exceptions_in_folder.
-
#exceptions ⇒ Object
readonly
Returns the value of attribute exceptions.
-
#specified_file ⇒ Object
readonly
Returns the value of attribute specified_file.
-
#unique_exception_types ⇒ Object
readonly
Returns the value of attribute unique_exception_types.
-
#unique_files ⇒ Object
readonly
Returns the value of attribute unique_files.
Class Method Summary collapse
Instance Method Summary collapse
- #count(type) ⇒ Object
- #display_blog ⇒ Object
- #display_exceptions_for_file(filename) ⇒ Object
- #display_file_does_not_exist(file) ⇒ Object
- #display_file_header(filename) ⇒ Object
- #display_file_trailer ⇒ Object
- #display_summary ⇒ Object
- #folder_exceptions ⇒ Object
- #header ⇒ Object
- #illegit_file?(file) ⇒ Boolean
-
#initialize(specified_file = nil) ⇒ Blog
constructor
A new instance of Blog.
- #legit_file?(file) ⇒ Boolean
- #read_exceptions_for_file(filename) ⇒ Object
Constructor Details
#initialize(specified_file = nil) ⇒ Blog
Returns a new instance of Blog.
14 15 16 17 18 19 20 |
# File 'lib/Blog.rb', line 14 def initialize(specified_file = nil) @exceptions = YAML.load_stream(File.read(FILE)) @unique_files = exceptions.map { |exc| exc.file }.uniq @count_and_files = "#{exceptions.length} in #{unique_files.join(' ')}" @unique_exception_types = exceptions.map { |exc| exc.type }.uniq @specified_file = specified_file end |
Instance Attribute Details
#count_and_files ⇒ Object (readonly)
Returns the value of attribute count_and_files.
6 7 8 |
# File 'lib/Blog.rb', line 6 def count_and_files @count_and_files end |
#count_of_exceptions_in_folder ⇒ Object (readonly)
Returns the value of attribute count_of_exceptions_in_folder.
6 7 8 |
# File 'lib/Blog.rb', line 6 def count_of_exceptions_in_folder @count_of_exceptions_in_folder end |
#exceptions ⇒ Object (readonly)
Returns the value of attribute exceptions.
6 7 8 |
# File 'lib/Blog.rb', line 6 def exceptions @exceptions end |
#specified_file ⇒ Object (readonly)
Returns the value of attribute specified_file.
6 7 8 |
# File 'lib/Blog.rb', line 6 def specified_file @specified_file end |
#unique_exception_types ⇒ Object (readonly)
Returns the value of attribute unique_exception_types.
6 7 8 |
# File 'lib/Blog.rb', line 6 def unique_exception_types @unique_exception_types end |
#unique_files ⇒ Object (readonly)
Returns the value of attribute unique_files.
6 7 8 |
# File 'lib/Blog.rb', line 6 def unique_files @unique_files end |
Class Method Details
.exceptions? ⇒ Boolean
90 91 92 93 94 95 |
# File 'lib/Blog.rb', line 90 def self.exceptions? unless File.exist?(FILE) puts NO_EXCEPTIONS else return true end end |
.generate_and_display_blog ⇒ Object
97 98 99 100 |
# File 'lib/Blog.rb', line 97 def self.generate_and_display_blog blog = self.new(ARGV[0]) blog.display_blog end |
Instance Method Details
#count(type) ⇒ Object
22 23 24 |
# File 'lib/Blog.rb', line 22 def count(type) exceptions.select { |exc| exc.type == type }.length end |
#display_blog ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/Blog.rb', line 72 def display_blog if legit_file?(specified_file) self.display_exceptions_for_file(specified_file) elsif illegit_file?(specified_file) self.display_file_does_not_exist(specified_file) else self.display_summary end end |
#display_exceptions_for_file(filename) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/Blog.rb', line 49 def display_exceptions_for_file(filename) file_exceptions = read_exceptions_for_file(filename) file_exceptions.each do |exc| display_file_header(filename) exc.display end display_file_trailer end |
#display_file_does_not_exist(file) ⇒ Object
68 69 70 |
# File 'lib/Blog.rb', line 68 def display_file_does_not_exist(file) puts "Sorry, #{file} is not a file in this folder." end |
#display_file_header(filename) ⇒ Object
58 59 60 61 62 |
# File 'lib/Blog.rb', line 58 def display_file_header(filename) puts "\n" puts "File: #{filename}" puts '-' * 15 end |
#display_file_trailer ⇒ Object
64 65 66 |
# File 'lib/Blog.rb', line 64 def display_file_trailer puts '-' * 15 end |
#display_summary ⇒ Object
40 41 42 43 |
# File 'lib/Blog.rb', line 40 def display_summary self.header self.folder_exceptions end |
#folder_exceptions ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/Blog.rb', line 31 def folder_exceptions unique_exception_types.each do |type| puts "\n" puts "Exception Class: #{type}" puts "Total: #{self.count(type)}" puts "-" * 15 end end |
#header ⇒ Object
26 27 28 29 |
# File 'lib/Blog.rb', line 26 def header system('clear') puts "Total Exceptions: #{count_and_files}" end |
#illegit_file?(file) ⇒ Boolean
86 87 88 |
# File 'lib/Blog.rb', line 86 def illegit_file?(file) file && !File.exist?(file) end |
#legit_file?(file) ⇒ Boolean
82 83 84 |
# File 'lib/Blog.rb', line 82 def legit_file?(file) file && File.exist?(file) end |
#read_exceptions_for_file(filename) ⇒ Object
45 46 47 |
# File 'lib/Blog.rb', line 45 def read_exceptions_for_file(filename) exceptions.select { |exc| exc.file == filename } end |