Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions ConfigFile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,32 @@ def initialize(file_string)
@lines = file_string
end

def load
process_lines(lines)
end
# maybe it's better to define "load" in subclasses so we can populate the subclass-specific member
# def load
# process_lines()
# end

def process_lines
#file_string is a string array,
#file_string is a string array,
#extendable_hash is a hash that is created through this method
@needed_lines = []
lines.each do |line|
unless line.length == 0 || line[0] == '#' #filters empty lines and comments
needed_lines = []
@lines.each do |line|
unless line.strip.length == 0 || line[0] == '#' #filters empty lines and comments
needed_lines << line
end
end

@hash = {}
needed_lines.map do |line| #splits every line at empty spaces
line.split
line = line.split(" ")
@hash[line[0]] = line.drop(1) #line.drop(1) returns line without the first (0th) entry
end

@hash = {}
needed_lines.map do |line|
hash[line[0]] => line.drop(1) #line.drop(1) returns line without the first (0th) entry
end

return hash
# needed_lines.map do |line|
# hash[line[0]] = line.drop(1) #line.drop(1) returns line without the first (0th) entry
# end

return @hash
end
end
end
21 changes: 21 additions & 0 deletions ConfigFileDriver.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# we can use this to test HttpdConfig.rb and MimeTypes.rb
#require_relative 'HttpdConfig'
require_relative 'MimeTypes'
class ConfigFileDriver

def start
lines_from_mime_types = IO.readlines "config/mime.types"
lines_from_httpd_config = IO.readlines "config/httpd.config"

#lines_from_httpd_config.each { |line| puts line }

# httpd_config = HttpdConfig.new( lines_from_mime_types )
# httpd_config.load

mime_types = MimeTypes.new( lines_from_mime_types )
mime_types.load
puts mime_types.for("html")
end

ConfigFileDriver.new().start
end
1 change: 1 addition & 0 deletions Headers_Collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ def add(key, value)
def to_s
@headers.map do |key, value|
"#{key}: #{value}"
end
end
end
12 changes: 12 additions & 0 deletions MimeTypes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require_relative 'ConfigFile'
class MimeTypes < ConfigFile


def load
@mime_types = process_lines()
end

def for(extension)
@mime_types[extension]
end
end
2 changes: 2 additions & 0 deletions config/httpd.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DocumentRoot /home/somewhere
ServerRoot /home/server
Loading