Class: CalExporter::Exporter

Inherits:
Object
  • Object
show all
Defined in:
lib/cal_exporter/exporter.rb

Instance Method Summary collapse

Constructor Details

#initialize(format, save_location) ⇒ Exporter

Returns a new instance of Exporter.



7
8
9
10
# File 'lib/cal_exporter/exporter.rb', line 7

def initialize(format, save_location)
  @format   = format
   @save_location = save_location
end

Instance Method Details

#save_as_jekyll(event) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/cal_exporter/exporter.rb', line 28

def save_as_jekyll(event)
  file_name = "#{@save_location}/#{event.dtstart.strftime('%Y-%m-%d')}-#{event.uid[0, 7]}.md"

  Dir.mkdir(@save_location) unless Dir.exist?(@save_location)

  f = File.open("#{file_name}", "w")
  f.write(to_jekyll(event))
  f.close 

  file_name
end

#to_jekyll(event) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/cal_exporter/exporter.rb', line 13

def to_jekyll(event)
   output_list = {
     "title"         => event.summary.gsub(/[|]|:/, '[' => '(', ']' => ')', ':' => ':'),
     "location"      => event.location.chomp,
     "date"          => event.dtstart.strftime('%Y-%m-%d'),
     "friendly_date" => event.dtstart.strftime('%A %d %b %Y'),  
     "link"          => url_list(event.description)[0],
     "layout"        => "post",
     "categories"    => "meetups"
   }

   output_list.to_yaml + "---\n#{event.description}"
end

#url_list(description) ⇒ Object



41
42
43
# File 'lib/cal_exporter/exporter.rb', line 41

def url_list(description)
  URI.extract(description, %w[http https])
end