Class: Ical2gcal::App
- Inherits:
-
Object
- Object
- Ical2gcal::App
- Defined in:
- lib/ical2gcal.rb
Instance Method Summary collapse
-
#calendars ⇒ Object
- return
-
Array.
-
#initialize ⇒ App
constructor
A new instance of App.
-
#opts ⇒ Object
- return
-
OptionParser.
- #run ⇒ Object
-
#set_credential(path) ⇒ Object
- param
-
String path [return] String.
Constructor Details
#initialize ⇒ App
Returns a new instance of App.
11 12 13 14 15 16 17 18 19 |
# File 'lib/ical2gcal.rb', line 11 def initialize @ics = nil @list = nil @calendars = nil @target = nil @credential = nil set_credential(Dir.pwd) end |
Instance Method Details
#calendars ⇒ Object
- return
-
Array
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/ical2gcal.rb', line 62 def calendars if ( @ics ) @calendars = @ics end if ( @list ) l = Ical2gcal::Ics::List.new( @list ).import @calendars = l.list end @calendars end |
#opts ⇒ Object
- return
-
OptionParser
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/ical2gcal.rb', line 77 def opts OptionParser.new do |opt| opt.on( '-c', '--calendar-id ID' ) { |c| @target = c } opt.on( '-i', '--ics URI' ) { |i| @ics = i } opt.on( '-l', '--calendar-list LIST' ) { |l| @list = l } opt.on( '-s', '--credential-store STORE' ) { |s| set_credential(s) } end end |
#run ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ical2gcal.rb', line 33 def run opts.parse( ARGV ) unless @target puts opts.help exit end if calendars cals = case calendars when Array calendars else [calendars] end g = Ical2gcal::Google.new(@target, @credential) g.remove_all_events cals.each { |c| Ical2gcal::Ics::Events.new( c ).each { |e| g.create_event( e ) } } else puts opts end end |
#set_credential(path) ⇒ Object
- param
-
String path
- return
-
String
25 26 27 28 29 30 31 |
# File 'lib/ical2gcal.rb', line 25 def set_credential(path) @credential = if File.directory?(path) File.join(path, '.ical2gcal_credential') else path end end |