class MoreHoliday::Importer
Attributes
content[R]
path[R]
stream[R]
year[R]
Public Class Methods
new(year = Date.today.year)
click to toggle source
# File lib/more_holiday/importer.rb, line 7 def initialize year = Date.today.year @year = year end
Public Instance Methods
from_file(path)
click to toggle source
# File lib/more_holiday/importer.rb, line 11 def from_file path @path = path @content = read_file end
from_stream(stream)
click to toggle source
# File lib/more_holiday/importer.rb, line 16 def from_stream stream @stream = stream @contect = read_stream end
Private Instance Methods
read_file()
click to toggle source
# File lib/more_holiday/importer.rb, line 23 def read_file File.open(path, "r") do |file| case File.extname(file).delete(".") when "ics" then Importers::ICal.new(File.read(file), year: year).serialize else file.close raise LoadError, "Type of file is not supported." end end end
read_stream()
click to toggle source
# File lib/more_holiday/importer.rb, line 34 def read_stream case true when stream.start_with?("BEGIN:VCALENDAR") Importers::ICal.new(stream, year: year).serialize else raise StreamContentTypeError, "Could not detect content type of stream" end end