Class: AddToGoogleCal::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/add_to_google_cal/builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object_or_hash) ⇒ Builder

Returns a new instance of Builder.



7
8
9
10
# File 'lib/add_to_google_cal/builder.rb', line 7

def initialize(object_or_hash)
  self.hash = object_or_hash
  validate!
end

Instance Attribute Details

#hashObject

Returns the value of attribute hash.



5
6
7
# File 'lib/add_to_google_cal/builder.rb', line 5

def hash
  @hash
end

Instance Method Details

#callObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/add_to_google_cal/builder.rb', line 16

def call
  attributes = {
    dates: "#{format_time(@hash[:dtstart])}/#{format_time(@hash[:dtend])}",
    text:  encode_string(@hash[:summary])
  }

  attributes.merge!(details:  encode_string(@hash[:description])) unless @hash[:description].blank?
  attributes.merge!(location: encode_string(@hash[:location]))    unless @hash[:location].blank?

  url = "https://www.google.com/calendar/render?action=TEMPLATE"

  attributes.each do |key, value|
    url << "&#{key}=#{value}"
  end

  url
end