waffle_cal 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +32 -0
- data/README.md +29 -0
- data/Rakefile +3 -0
- data/lib/waffle_cal.rb +4 -0
- data/lib/waffle_cal/calendar.rb +49 -0
- data/lib/waffle_cal/errors.rb +10 -0
- data/lib/waffle_cal/event.rb +72 -0
- data/lib/waffle_cal/prod_id.rb +34 -0
- data/lib/waffle_cal/version.rb +3 -0
- data/spec/calendar_spec.rb +38 -0
- data/spec/event_spec.rb +40 -0
- data/spec/prod_id_spec.rb +22 -0
- data/spec/spec_helper.rb +1 -0
- data/tasks/rspec.rake +3 -0
- data/waffle_cal.gemspec +24 -0
- metadata +107 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4b0aa1260e460020871a469f486a060baeab4b96
|
4
|
+
data.tar.gz: f83962872b6672154a89848de9431dba068bfc2d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cad59ec0b4d1c93486e63637c4872dcdc1336dadd242e2c59f144c67cbf8d2050758a88ea652c809c4d262a1253ebaefcf0acd652f54ab88ed30e64bf2d76587
|
7
|
+
data.tar.gz: 36111d91437b54d987346a5fcaceebfb7c6eb2fba2eeadd89d459c503d3ec09192c9baf90a865b823ab88682bf5601019d30b9d17eceee4dc58d7e0b46c4044e
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
./bundle
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
waffle_cal (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.2.5)
|
10
|
+
rake (10.4.2)
|
11
|
+
rspec (3.2.0)
|
12
|
+
rspec-core (~> 3.2.0)
|
13
|
+
rspec-expectations (~> 3.2.0)
|
14
|
+
rspec-mocks (~> 3.2.0)
|
15
|
+
rspec-core (3.2.3)
|
16
|
+
rspec-support (~> 3.2.0)
|
17
|
+
rspec-expectations (3.2.1)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.2.0)
|
20
|
+
rspec-mocks (3.2.1)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.2.0)
|
23
|
+
rspec-support (3.2.2)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (~> 1.5)
|
30
|
+
rake (~> 10)
|
31
|
+
rspec (~> 3.2)
|
32
|
+
waffle_cal!
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# WaffleCal
|
2
|
+
A simple iCal/vCal generator.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
Once the gem has been added to your Gemfile and you’ve updated your bundle, you can create calendars like this:
|
6
|
+
|
7
|
+
calendar_id = WaffleCal::ProdId.create(‘my_entity’, ‘my_product’, ‘en’)
|
8
|
+
calendar = WaffleCal::Calendar.new(calendar_id)
|
9
|
+
|
10
|
+
Create events like this:
|
11
|
+
|
12
|
+
event = WaffleCal::Event.new(params)
|
13
|
+
|
14
|
+
where `params` is a `Hash` with these keys:
|
15
|
+
|
16
|
+
* uid: A unique identifier (mandatory)
|
17
|
+
* start_time: An instance of `Time` representing when the event starts (mandatory)
|
18
|
+
* end_time: An instace of `Time` representing when the event ends (mandatory)
|
19
|
+
* summary: The title/headline of the event (mandatory)
|
20
|
+
* description: A longer textual description (optional)
|
21
|
+
* location: Where the event is held. Can either be text or coordinates (optional).
|
22
|
+
|
23
|
+
Add the event to your calendar like this:
|
24
|
+
|
25
|
+
calendar << event
|
26
|
+
|
27
|
+
In the end, serialize the calendar to a `String` with `to_s`:
|
28
|
+
|
29
|
+
puts calendar.to_s
|
data/Rakefile
ADDED
data/lib/waffle_cal.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
module WaffleCal
|
2
|
+
|
3
|
+
class Calendar
|
4
|
+
|
5
|
+
attr_accessor :prod_id, :events
|
6
|
+
|
7
|
+
def initialize(prod_id=nil)
|
8
|
+
@prod_id = prod_id
|
9
|
+
end
|
10
|
+
|
11
|
+
def <<(event)
|
12
|
+
add_event(event)
|
13
|
+
end
|
14
|
+
|
15
|
+
def add_event(event)
|
16
|
+
@events ||= []
|
17
|
+
@events << event
|
18
|
+
end
|
19
|
+
|
20
|
+
def events
|
21
|
+
@events || []
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_s
|
25
|
+
output = []
|
26
|
+
|
27
|
+
output += start_calendar
|
28
|
+
output += events.collect { |evt| evt.to_s }
|
29
|
+
output += end_calendar
|
30
|
+
|
31
|
+
output.join("\r\n")
|
32
|
+
end
|
33
|
+
|
34
|
+
protected
|
35
|
+
|
36
|
+
def start_calendar
|
37
|
+
output = []
|
38
|
+
output << "BEGIN:VCALENDAR"
|
39
|
+
output << "VERSION:2.0"
|
40
|
+
output << "METHOD:PUBLISH"
|
41
|
+
output << "PRODID:-#{@prod_id.to_s}"
|
42
|
+
output
|
43
|
+
end
|
44
|
+
|
45
|
+
def end_calendar
|
46
|
+
["END:VCALENDAR"]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module WaffleCal
|
2
|
+
|
3
|
+
class Event
|
4
|
+
|
5
|
+
attr_accessor :uid, :start_time, :end_time, :summary, :description, :location
|
6
|
+
|
7
|
+
@@time_format = "%Y%m%dT%H%M00"
|
8
|
+
|
9
|
+
def initialize(attrs={})
|
10
|
+
attrs.each { |key, val| self.send("#{key}=", val) }
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_s
|
14
|
+
valid?
|
15
|
+
|
16
|
+
output = []
|
17
|
+
output << start_event
|
18
|
+
output << date_start_str
|
19
|
+
output << date_end_str
|
20
|
+
output << uid_str
|
21
|
+
output << summary_str if summary
|
22
|
+
output << location_str if location
|
23
|
+
output << description_str if description
|
24
|
+
output << end_event
|
25
|
+
output.join("\r\n")
|
26
|
+
end
|
27
|
+
|
28
|
+
protected
|
29
|
+
|
30
|
+
def valid?
|
31
|
+
raise Errors::IncompleteEventError.new('Missing uid') if uid.nil?
|
32
|
+
raise Errors::IncompleteEventError.new('Missing start time') if start_time.nil?
|
33
|
+
raise Errors::IncompleteEventError.new('Missing end time') if end_time.nil?
|
34
|
+
raise Errors::IncompleteEventError.new('Missing summary') if summary.nil?
|
35
|
+
raise Errors::IncompleteEventError.new('Start time is not an instance of Time') unless start_time.instance_of?(Time)
|
36
|
+
raise Errors::IncompleteEventError.new('End time is not an instance of Time') unless end_time.instance_of?(Time)
|
37
|
+
raise Errors::IllegalEventError.new('End time is before start time') if start_time > end_time
|
38
|
+
end
|
39
|
+
|
40
|
+
def date_start_str
|
41
|
+
"DTSTART:#{start_time.strftime(@@time_format)}"
|
42
|
+
end
|
43
|
+
|
44
|
+
def date_end_str
|
45
|
+
"DTEND:#{end_time.strftime(@@time_format)}"
|
46
|
+
end
|
47
|
+
|
48
|
+
def uid_str
|
49
|
+
"UID:#{uid}"
|
50
|
+
end
|
51
|
+
|
52
|
+
def summary_str
|
53
|
+
"SUMMARY:#{summary}"
|
54
|
+
end
|
55
|
+
|
56
|
+
def location_str
|
57
|
+
"LOCATION:#{location}"
|
58
|
+
end
|
59
|
+
|
60
|
+
def description_str
|
61
|
+
"DESCRIPTION:#{description}"
|
62
|
+
end
|
63
|
+
|
64
|
+
def start_event
|
65
|
+
"BEGIN:VEVENT"
|
66
|
+
end
|
67
|
+
|
68
|
+
def end_event
|
69
|
+
"END:VEVENT"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module WaffleCal
|
2
|
+
|
3
|
+
class ProdId
|
4
|
+
attr_accessor :entity_name, :product_name, :language
|
5
|
+
|
6
|
+
def initialize(attrs={})
|
7
|
+
@entity_name = attrs[:entity_name]
|
8
|
+
@product_name = attrs[:product_name]
|
9
|
+
@language = attrs[:language].upcase if attrs.has_key?(:language)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.create(entity_name, product_name, language)
|
13
|
+
ProdId.new({entity_name: entity_name, product_name: product_name, language: language})
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_s
|
17
|
+
if complete?
|
18
|
+
"//#{@entity_name}//#{@product_name}//#{@language}"
|
19
|
+
else
|
20
|
+
default_prod_id.to_s
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def complete?
|
27
|
+
@entity_name && @product_name && @language
|
28
|
+
end
|
29
|
+
|
30
|
+
def default_prod_id
|
31
|
+
ProdId.new({entity_name: 'fiskeben.dk', product_name: 'waffle_cal', language: 'EN'})
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe WaffleCal::Calendar do
|
4
|
+
subject { WaffleCal::Calendar.new }
|
5
|
+
|
6
|
+
describe '#to_s' do
|
7
|
+
it 'returns a vcalendar string' do
|
8
|
+
expect(subject.to_s).to be_a(String)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '<<' do
|
13
|
+
it 'adds an event' do
|
14
|
+
subject << WaffleCal::Event.new
|
15
|
+
expect(subject.events.length).to eq(1)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'add_event' do
|
20
|
+
it 'adds an event' do
|
21
|
+
subject.add_event(WaffleCal::Event.new)
|
22
|
+
expect(subject.events.length).to eq(1)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'events' do
|
27
|
+
it 'returns a list of events' do
|
28
|
+
expect(subject.events).to be_an(Array)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'returns all events' do
|
32
|
+
subject << WaffleCal::Event.new
|
33
|
+
expect(subject.events.first).to be_an(WaffleCal::Event)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
end
|
data/spec/event_spec.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe WaffleCal::Event do
|
4
|
+
|
5
|
+
it 'serializes to string' do
|
6
|
+
event = WaffleCal::Event.new({uid: 'my-uid', start_time: Time.now - 100, end_time: Time.now + 100, summary: 'Some event', description: 'Very event', location: 'Moon'})
|
7
|
+
expect(event.to_s).to be_a(String)
|
8
|
+
end
|
9
|
+
|
10
|
+
context 'validation' do
|
11
|
+
|
12
|
+
it 'raises error if uid is missing' do
|
13
|
+
event = WaffleCal::Event.new({start_time: Time.now, end_time: Time.now + 100, summary: 'Some event', description: 'Very event', location: 'Moon'})
|
14
|
+
expect { event.to_s }.to raise_error(WaffleCal::Errors::IncompleteEventError)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'raises error if start_time is missing' do
|
18
|
+
event = WaffleCal::Event.new({uid: 'my-uid', end_time: Time.now + 100, summary: 'Some event', description: 'Very event', location: 'Moon'})
|
19
|
+
expect { event.to_s }.to raise_error(WaffleCal::Errors::IncompleteEventError)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'raises error if end_time is missing' do
|
23
|
+
event = WaffleCal::Event.new({uid: 'my-uid', start_time: Time.now, summary: 'Some event', description: 'Very event', location: 'Moon'})
|
24
|
+
expect { event.to_s }.to raise_error(WaffleCal::Errors::IncompleteEventError)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'raises error if summary is missing' do
|
28
|
+
event = WaffleCal::Event.new({uid: 'my-uid', start_time: Time.now, end_time: Time.now + 100, description: 'Very event', location: 'Moon'})
|
29
|
+
expect { event.to_s }.to raise_error(WaffleCal::Errors::IncompleteEventError)
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
it 'raises error if end time is before start time' do
|
34
|
+
event = WaffleCal::Event.new({uid: 'my-uid', start_time: Time.now, end_time: Time.now - 100, summary: 'Some event', description: 'Very event', location: 'Moon'})
|
35
|
+
expect { event.to_s }.to raise_error(WaffleCal::Errors::IllegalEventError)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe WaffleCal::ProdId do
|
4
|
+
|
5
|
+
context 'validation' do
|
6
|
+
|
7
|
+
let (:valid_id) { id = WaffleCal::ProdId.new({entity_name: 'foo', product_name: 'bar', language: 'en'}) }
|
8
|
+
|
9
|
+
it 'returns an ID string if complete' do
|
10
|
+
expect(valid_id.to_s).to eq('//foo//bar//EN')
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'uppercases language' do
|
14
|
+
expect(valid_id.language).to eq('EN')
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'returns default ID string if not complete' do
|
18
|
+
expect(WaffleCal::ProdId.new.to_s).to eq('//fiskeben.dk//waffle_cal//EN')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'waffle_cal'
|
data/tasks/rspec.rake
ADDED
data/waffle_cal.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'waffle_cal/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "waffle_cal"
|
8
|
+
spec.version = WaffleCal::VERSION
|
9
|
+
spec.authors = ["Ricco Førgaard"]
|
10
|
+
spec.email = ["ricco@fiskeben.dk"]
|
11
|
+
spec.summary = "Vcal/ical creator"
|
12
|
+
spec.description = "Creates ical/vcal files."
|
13
|
+
spec.homepage = "http://fiskeben.dk"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake", "~> 10"
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.2"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: waffle_cal
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ricco Førgaard
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.2'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.2'
|
55
|
+
description: Creates ical/vcal files.
|
56
|
+
email:
|
57
|
+
- ricco@fiskeben.dk
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- Gemfile.lock
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/waffle_cal.rb
|
68
|
+
- lib/waffle_cal/calendar.rb
|
69
|
+
- lib/waffle_cal/errors.rb
|
70
|
+
- lib/waffle_cal/event.rb
|
71
|
+
- lib/waffle_cal/prod_id.rb
|
72
|
+
- lib/waffle_cal/version.rb
|
73
|
+
- spec/calendar_spec.rb
|
74
|
+
- spec/event_spec.rb
|
75
|
+
- spec/prod_id_spec.rb
|
76
|
+
- spec/spec_helper.rb
|
77
|
+
- tasks/rspec.rake
|
78
|
+
- waffle_cal.gemspec
|
79
|
+
homepage: http://fiskeben.dk
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.2.2
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: Vcal/ical creator
|
103
|
+
test_files:
|
104
|
+
- spec/calendar_spec.rb
|
105
|
+
- spec/event_spec.rb
|
106
|
+
- spec/prod_id_spec.rb
|
107
|
+
- spec/spec_helper.rb
|