eventdb 0.7.1 → 1.0.0
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 +4 -4
- data/Manifest.txt +1 -0
- data/README.md +119 -85
- data/lib/eventdb/database.rb +9 -1
- data/lib/eventdb/models.rb +28 -48
- data/lib/eventdb/reader.rb +42 -31
- data/lib/eventdb/version.rb +3 -3
- data/test/data/RUBY.md +22 -379
- data/test/templates/RUBY.md.erb +4 -4
- data/test/test_calendar.rb +5 -9
- data/test/test_database.rb +4 -8
- data/test/test_parser.rb +83 -0
- data/test/test_reader.rb +12 -15
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e67f167886afaad736928ea7019c69acf0f0fbcc
|
4
|
+
data.tar.gz: 69a6a122068e5610f370321f1e23025850f5e63a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f39c98b61f4b5082bf7521e30021be2343d08580d077b5580302eb0add55662ee7c54a8b64430389ec56bee5e5b37a9cec589ae1c9c7bc81f657c563baa95ab
|
7
|
+
data.tar.gz: 472c4751d6849259b130eb2e8d67315614b501b2dc6846ec1154912aa6eb2ad47c4534028cebd01c2365fc143545499b2f67f9faea6a01c18a60e46d3390f3d8
|
data/Manifest.txt
CHANGED
data/README.md
CHANGED
@@ -17,43 +17,135 @@ moved to its own gem, that is, whatson.
|
|
17
17
|
See the [whatson project for more »](https://github.com/textkit/whatson)
|
18
18
|
|
19
19
|
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
``` ruby
|
23
|
+
url = "https://github.com/planetruby/calendar/raw/master/_data/conferences2020.yml"
|
24
|
+
|
25
|
+
db = EventDb::Memory.new # note: use in-memory SQLite database
|
26
|
+
db.read( url )
|
27
|
+
|
28
|
+
today = Date.today
|
29
|
+
|
30
|
+
puts 'Upcoming Ruby Conferences:'
|
31
|
+
puts ''
|
32
|
+
|
33
|
+
on = EventDb::Model::Event.live( today )
|
34
|
+
on.each do |e|
|
35
|
+
puts " NOW ON #{current_day(today)}d #{e.title} #{e.start_date.year}, #{e.date_fmt} (#{e.days}d) @ #{e.place}"
|
36
|
+
end
|
37
|
+
|
38
|
+
puts '' if on.any?
|
39
|
+
|
40
|
+
up = EventDb::Model::Event.limit( 17 ).upcoming( today )
|
41
|
+
up.each do |e|
|
42
|
+
puts " in #{diff_days(today)}d #{e.title}, #{e.date_fmt} (#{e.days}d) @ #{e.place}"
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
|
47
|
+
will print in 2020:
|
48
|
+
|
49
|
+
```
|
50
|
+
Upcoming Ruby Conferences:
|
51
|
+
|
52
|
+
in 62d Rubyfuza, Thu-Sat Feb/6-8 (3d) @ Cape Town, South Africa
|
53
|
+
in 74d ParisRB Conf, Tue+Wed Feb/18+19 (2d) @ Paris, France
|
54
|
+
in 76d RubyConf Australia, Thu+Fri Feb/20+21 (2d) @ Melbourne, Victoria, Australia
|
55
|
+
in 105d Wrocław <3 Ruby (wroclove.rb), Fri-Sun Mar/20-22 (3d) @ Wrocław, Poland
|
56
|
+
in 118d RubyDay Italy, Thu Apr/2 (1d) @ Verona, Veneto, Italy
|
57
|
+
in 125d RubyKaigi, Thu-Sat Apr/9-11 (3d) @ Nagano, Japan
|
58
|
+
in 141d RubyConf India, Sat+Sun Apr/25+26 (2d) @ Goa, India
|
59
|
+
in 151d RailsConf (United States), Tue-Thu May/5-7 (3d) @ Portland, Oregon, United States
|
60
|
+
in 161d Balkan Ruby, Fri+Sat May/15+16 (2d) @ Sofia, Bulgaria
|
61
|
+
in 183d Ruby Unconf Hamburg, Sat+Sun Jun/6+7 (2d) @ Hamburg, Germany
|
62
|
+
in 210d Brighton RubyConf, Fri Jul/3 (1d) @ Brighton, Sussex, England, United Kingdom
|
63
|
+
in 230d RubyConf Kenya, Thu-Sat Jul/23-25 (3d) @ Nairobi, Kenya
|
64
|
+
in 259d European Ruby Konference (EuRuKo), Fri+Sat Aug/21+22 (2d) @ Helsinki, Finnland
|
65
|
+
in 347d RubyConf (United States), Tue-Thu Nov/17-19 (3d) @ Houston, Texas, United States
|
66
|
+
```
|
67
|
+
|
68
|
+
and back in 2015
|
69
|
+
|
70
|
+
```
|
71
|
+
Upcoming Ruby Conferences:
|
72
|
+
|
73
|
+
NOW ON 2d RubyMotion Conference - #inspect, Wed+Thu Jul/1+2 (2d) @ Paris, France
|
74
|
+
|
75
|
+
in 18d Brighton Ruby Conference, Mon Jul/20 (1d) @ Brighton, East Sussex, England
|
76
|
+
in 27d European Ruby Camp - eurucamp, Fri-Sun Jul/31-Aug/2 (3d) @ Berlin (Potsdam), Germany
|
77
|
+
in 27d JRuby Conference Europe - JRubyConf EU, Fri Jul/31 (1d) @ Berlin (Potsdam), Germany
|
78
|
+
in 28d Burlington Ruby Conference, Sat+Sun Aug/1+2 (2d) @ Burlington, Vermont, New England, United States
|
79
|
+
in 50d Madison+ Ruby, Fri+Sat Aug/21+22 (2d) @ Madison, Wisconsin, Great Lakes, United States
|
80
|
+
in 71d RubyConf Taiwan, Fri+Sat Sep/11+12 (2d) @ Taipei, Taiwan
|
81
|
+
in 72d RubyConf Portugal, Mon+Tue Sep/14+15 (2d) @ Braga, Portugal
|
82
|
+
in 78d RubyConf Brasil, Fri+Sat Sep/18+19 (2d) @ São Paulo, Brazil
|
83
|
+
in 83d Rocky Mountain Ruby Conference, Wed-Fri Sep/23-25 (3d) @ Boulder, Colorado, Rocky Mountains, United States
|
84
|
+
in 85d Ruby Open Source Software (ROSS) Conference - ROSSConf, Sat Sep/26 (1d) @ Berlin, Germany
|
85
|
+
in 93d ArrrCamp, Thu+Fri Oct/1+2 (2d) @ Ghent, Oost-Vlaanderen, Belgium
|
86
|
+
in 105d RubyConf Colombia, Thu+Fri Oct/15+16 (2d) @ Medellin, Colombia
|
87
|
+
in 107d European Ruby Konference - EuRuKo, Sat+Sun Oct/17+18 (2d) @ Salzburg, Austria
|
88
|
+
in 132d RubyWorld Conference, Wed+Thu Nov/11+12 (2d) @ Matsue, Japan
|
89
|
+
...
|
90
|
+
```
|
91
|
+
|
92
|
+
|
20
93
|
## Format
|
21
94
|
|
22
95
|
**Markdown**
|
23
96
|
|
24
|
-
Option
|
97
|
+
Option 1a) Classic Style
|
25
98
|
|
26
|
-
|
99
|
+
``` markdown
|
27
100
|
- [European Ruby Konference - EuRuKo](http://euruko.org)
|
28
|
-
-
|
29
|
-
|
101
|
+
- 2020 @ Helsinki, Finnland; Aug/21+22
|
102
|
+
```
|
30
103
|
|
31
|
-
Option
|
104
|
+
Option 1b) Modern Style
|
32
105
|
|
33
|
-
|
106
|
+
``` markdown
|
34
107
|
- **European Ruby Konference - EuRuKo** (web: [euruko.org](http://euruko.org))
|
35
|
-
-
|
36
|
-
|
108
|
+
- 2020 @ Helsinki, Finnland; Aug/21+22
|
109
|
+
```
|
110
|
+
|
111
|
+
**YAML**
|
112
|
+
|
113
|
+
Option 2a) Classic Style A
|
114
|
+
|
115
|
+
``` yaml
|
116
|
+
- title: European Ruby Konference - EuRuKo
|
117
|
+
link: http://euruko.org
|
118
|
+
place: Helsinki, Finnland
|
119
|
+
start_date: 2020-08-21
|
120
|
+
end_date: 2020-08-22
|
121
|
+
```
|
122
|
+
|
123
|
+
Option 2b) Classic Style B
|
124
|
+
|
125
|
+
``` yaml
|
126
|
+
- name: European Ruby Konference - EuRuKo
|
127
|
+
url: http://euruko.org
|
128
|
+
location: Helsinki, Finnland
|
129
|
+
start: 2020-08-21
|
130
|
+
end: 2020-08-22
|
131
|
+
```
|
132
|
+
|
37
133
|
|
38
134
|
resulting in:
|
39
135
|
|
40
|
-
|
41
|
-
#<
|
42
|
-
id: 1,
|
136
|
+
```
|
137
|
+
#<Event
|
43
138
|
title: "European Ruby Konference - EuRuKo",
|
44
139
|
link: "http://euruko.org",
|
45
|
-
place: "
|
46
|
-
start_date:
|
47
|
-
end_date:
|
48
|
-
|
49
|
-
created_at: 2015-07-12 08:51:52 UTC,
|
50
|
-
updated_at: 2015-07-12 08:51:52 UTC>
|
51
|
-
~~~
|
140
|
+
place: "Helsinki, Finnland",
|
141
|
+
start_date: Fri, 21 Aug 2020,
|
142
|
+
end_date: Sat, 22 Aug 2020>
|
143
|
+
```
|
52
144
|
|
53
145
|
Note: The headings hierarchy (starting w/ heading level 2) gets added to the place as a
|
54
146
|
geo tree. Example:
|
55
147
|
|
56
|
-
|
148
|
+
``` markdown
|
57
149
|
## Europe
|
58
150
|
|
59
151
|
### Central Europe
|
@@ -63,78 +155,21 @@ geo tree. Example:
|
|
63
155
|
##### Bavaria
|
64
156
|
|
65
157
|
###### Upper Franconia
|
66
|
-
|
158
|
+
```
|
67
159
|
|
68
160
|
resulting in:
|
69
161
|
|
70
|
-
|
71
|
-
Upper Franconia
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
## Usage
|
76
|
-
|
77
|
-
~~~
|
78
|
-
url = "https://github.com/planetruby/awesome-events/raw/master/README.md"
|
79
|
-
|
80
|
-
r = EventDb::EventReader.from_url( url )
|
81
|
-
events = r.read
|
82
|
-
|
83
|
-
db = EventDb::MemDatabase.new # note: use in-memory SQLite database
|
84
|
-
db.add( events )
|
85
|
-
|
86
|
-
|
87
|
-
today = Date.today
|
88
|
-
|
89
|
-
puts 'Upcoming Ruby Conferences:'
|
90
|
-
puts ''
|
91
|
-
|
92
|
-
on = EventDb::Model::Event.live( today )
|
93
|
-
on.each do |e|
|
94
|
-
current_day = today.mjd - e.start_date.mjd + 1 # calculate current event day (1,2,3,etc.)
|
95
|
-
puts " NOW ON #{current_day}d #{e.title} #{e.start_date.year}, #{e.date_str} (#{e.days}d) @ #{e.place}"
|
96
|
-
end
|
97
|
-
|
98
|
-
puts '' if on.any?
|
99
|
-
|
100
|
-
up = EventDb::Model::Event.limit( 17 ).upcoming( today )
|
101
|
-
up.each do |e|
|
102
|
-
diff_days = e.start_date.mjd - today.mjd # note: mjd == Modified Julian Day Number
|
103
|
-
puts " in #{diff_days}d #{e.title}, #{e.date_str} (#{e.days}d) @ #{e.place}"
|
104
|
-
end
|
105
|
-
~~~
|
106
|
-
|
107
|
-
will print:
|
108
|
-
|
109
|
-
~~~
|
110
|
-
Upcoming Ruby Conferences:
|
111
|
-
|
112
|
-
NOW ON 2d RubyMotion Conference - #inspect, Wed+Thu Jul/1+2 (2d) @ Paris, France › Europe
|
113
|
-
|
114
|
-
in 18d Brighton Ruby Conference, Mon Jul/20 (1d) @ Brighton, East Sussex › England (en) › Western Europe › Europe
|
115
|
-
in 27d European Ruby Camp - eurucamp, Fri-Sun Jul/31-Aug/2 (3d) @ Berlin (Potsdam), Germany › Europe
|
116
|
-
in 27d JRuby Conference Europe - JRubyConf EU, Fri Jul/31 (1d) @ Berlin (Potsdam), Germany › Europe
|
117
|
-
in 28d Burlington Ruby Conference, Sat+Sun Aug/1+2 (2d) @ Burlington, Vermont › New England › United States (us) › North America › America
|
118
|
-
in 50d Madison+ Ruby, Fri+Sat Aug/21+22 (2d) @ Madison, Wisconsin › Great Lakes › United States (us) › North America › America
|
119
|
-
in 61d Full Stack Fest - Barcelona Ruby Conference (BaRuCo) + Barcelona Future JS, Tue-Sat Sep/1-5 (5d) @ Barcelona, Catalonia › Spain / España (es) › Southern Europe › Europe
|
120
|
-
in 71d RubyConf Taiwan, Fri+Sat Sep/11+12 (2d) @ Taipei › Taiwan (tw) › Asia
|
121
|
-
in 72d RubyConf Portugal, Mon+Tue Sep/14+15 (2d) @ Braga › Portugal (pt) › Southern Europe › Europe
|
122
|
-
in 78d RubyConf Brasil, Fri+Sat Sep/18+19 (2d) @ São Paulo › Brazil / Brasil (br) › South America › America
|
123
|
-
in 83d Rocky Mountain Ruby Conference, Wed-Fri Sep/23-25 (3d) @ Boulder, Colorado › Rocky Mountains › United States (us) › North America › America
|
124
|
-
in 85d Ruby Open Source Software (ROSS) Conference - ROSSConf, Sat Sep/26 (1d) @ Berlin, Germany › Europe
|
125
|
-
in 93d ArrrCamp, Thu+Fri Oct/1+2 (2d) @ Ghent, Oost-Vlaanderen › Belgium / België / Belgique (be) › Western Europe › Europe
|
126
|
-
in 105d RubyConf Colombia, Thu+Fri Oct/15+16 (2d) @ Medellin › Colombia (co) › South America › America
|
127
|
-
in 107d European Ruby Konference - EuRuKo, Sat+Sun Oct/17+18 (2d) @ Salzburg, Austria › Europe
|
128
|
-
in 132d RubyWorld Conference, Wed+Thu Nov/11+12 (2d) @ Matsue › Japan (jp) › Asia
|
129
|
-
...
|
130
|
-
~~~
|
162
|
+
```
|
163
|
+
Upper Franconia, Bavaria, Germany, Central Europe, Europe
|
164
|
+
```
|
131
165
|
|
132
166
|
|
133
167
|
## Public Event Datasets
|
134
168
|
|
135
|
-
- [
|
136
|
-
- [calendar @
|
137
|
-
- [calendar @
|
169
|
+
- [calendar @ Planet Ruby](https://github.com/planetruby/calendar) - a collection of awesome Ruby events (meetups, conferences, camps, etc.) from around the world
|
170
|
+
- [calendar @ World Football Book](https://github.com/footballbook/calendar) - a collection of awesome football tournaments, cups, etc. from around the world
|
171
|
+
- [calendar @ World Beer Book](https://github.com/beerbook/calendar) - a collection of awesome beer events (oktoberfest, starkbierfest, etc.) from around the world
|
172
|
+
|
138
173
|
|
139
174
|
|
140
175
|
## Install
|
@@ -154,4 +189,3 @@ Use it as you please with no restrictions whatsoever.
|
|
154
189
|
|
155
190
|
Send them along to the ruby-talk mailing list.
|
156
191
|
Thanks!
|
157
|
-
|
data/lib/eventdb/database.rb
CHANGED
@@ -23,9 +23,17 @@ class Database
|
|
23
23
|
create
|
24
24
|
end
|
25
25
|
|
26
|
+
|
27
|
+
def read( path ) ## path_or_url
|
28
|
+
events = EventReader.read( path )
|
29
|
+
add( events )
|
30
|
+
end
|
31
|
+
|
26
32
|
def add( events )
|
27
33
|
## todo/fix: add check if Array and also allow single event
|
28
|
-
## change arg to event_or_events
|
34
|
+
## change arg to event_or_events - why? why not?
|
35
|
+
|
36
|
+
## todo/fix: use attributes or to_hash or somehting that works with ActiveRecord and Struct objects - why? why not?
|
29
37
|
|
30
38
|
events.each do |ev|
|
31
39
|
Model::Event.create!(
|
data/lib/eventdb/models.rb
CHANGED
@@ -8,63 +8,43 @@ class Event < ActiveRecord::Base
|
|
8
8
|
## todo: auto-add today ?? - why, why not?
|
9
9
|
## move order('start_date') into its own scope ??
|
10
10
|
|
11
|
-
scope :upcoming, ->(today) { order('start_date').where( 'start_date > ?', today ) }
|
11
|
+
scope :upcoming, ->( today=Date.today ) { order('start_date').where( 'start_date > ?', today ) }
|
12
12
|
|
13
13
|
## rename to now_on/on_now/now_playing/running/etc. - why? why not??
|
14
|
-
scope :live, ->(today) { order('start_date').where( 'start_date <= ? AND end_date >= ?', today, today ) }
|
14
|
+
scope :live, ->( today=Date.today ) { order('start_date').where( 'start_date <= ? AND end_date >= ?', today, today ) }
|
15
15
|
|
16
16
|
|
17
|
+
def current_day( today=Date.today )
|
18
|
+
today.mjd - start_date.mjd + 1 # calculate current event day (1,2,3,etc.)
|
19
|
+
end
|
20
|
+
alias_method :cur_day, :current_day
|
17
21
|
|
18
|
-
|
19
|
-
|
20
|
-
if days == 1
|
21
|
-
buf = ''
|
22
|
-
buf << Date::ABBR_MONTHNAMES[start_date.month]
|
23
|
-
buf << '/'
|
24
|
-
buf << start_date.day.to_s
|
25
|
-
elsif days == 2
|
26
|
-
buf = ''
|
27
|
-
buf << Date::ABBR_MONTHNAMES[start_date.month]
|
28
|
-
buf << '/'
|
29
|
-
buf << start_date.day.to_s
|
30
|
-
buf << '+'
|
31
|
-
if start_date.month != end_date.month
|
32
|
-
buf << Date::ABBR_MONTHNAMES[end_date.month]
|
33
|
-
buf << '/'
|
34
|
-
end
|
35
|
-
buf << end_date.day.to_s
|
36
|
-
else ## assume multi day
|
37
|
-
buf = ''
|
38
|
-
buf << Date::ABBR_MONTHNAMES[start_date.month]
|
39
|
-
buf << '/'
|
40
|
-
buf << start_date.day.to_s
|
41
|
-
buf << '-'
|
42
|
-
if start_date.month != end_date.month
|
43
|
-
buf << Date::ABBR_MONTHNAMES[end_date.month]
|
44
|
-
buf << '/'
|
45
|
-
end
|
46
|
-
buf << end_date.day.to_s
|
47
|
-
end
|
48
|
-
|
49
|
-
buf
|
22
|
+
def diff_days( today=Date.today )
|
23
|
+
start_date.mjd - today.mjd # note: mjd == Modified Julian Day Number
|
50
24
|
end
|
51
25
|
|
52
|
-
|
26
|
+
|
27
|
+
|
28
|
+
def date_fmt( fmt='long' ) # date pretty printed (pre-formatted) as string (with weeknames)
|
53
29
|
|
54
30
|
## note: wday - (0-6, Sunday is zero).
|
55
31
|
if days == 1
|
56
32
|
buf = ''
|
57
|
-
|
58
|
-
|
33
|
+
if fmt == 'long'
|
34
|
+
buf << Date::ABBR_DAYNAMES[start_date.wday]
|
35
|
+
buf << ' '
|
36
|
+
end
|
59
37
|
buf << Date::ABBR_MONTHNAMES[start_date.month]
|
60
38
|
buf << '/'
|
61
39
|
buf << start_date.day.to_s
|
62
40
|
elsif days == 2
|
63
41
|
buf = ''
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
42
|
+
if fmt == 'long'
|
43
|
+
buf << Date::ABBR_DAYNAMES[start_date.wday]
|
44
|
+
buf << '+'
|
45
|
+
buf << Date::ABBR_DAYNAMES[end_date.wday]
|
46
|
+
buf << ' '
|
47
|
+
end
|
68
48
|
buf << Date::ABBR_MONTHNAMES[start_date.month]
|
69
49
|
buf << '/'
|
70
50
|
buf << start_date.day.to_s
|
@@ -76,10 +56,12 @@ class Event < ActiveRecord::Base
|
|
76
56
|
buf << end_date.day.to_s
|
77
57
|
else ## assume multi day
|
78
58
|
buf = ''
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
59
|
+
if fmt == 'long'
|
60
|
+
buf << Date::ABBR_DAYNAMES[start_date.wday]
|
61
|
+
buf << '-'
|
62
|
+
buf << Date::ABBR_DAYNAMES[end_date.wday]
|
63
|
+
buf << ' '
|
64
|
+
end
|
83
65
|
buf << Date::ABBR_MONTHNAMES[start_date.month]
|
84
66
|
buf << '/'
|
85
67
|
buf << start_date.day.to_s
|
@@ -92,9 +74,7 @@ class Event < ActiveRecord::Base
|
|
92
74
|
end
|
93
75
|
|
94
76
|
buf
|
95
|
-
end # method
|
96
|
-
|
97
|
-
|
77
|
+
end # method date_fmt
|
98
78
|
end # class Event
|
99
79
|
|
100
80
|
end # module Model
|
data/lib/eventdb/reader.rb
CHANGED
@@ -11,47 +11,55 @@ class EventReader
|
|
11
11
|
:start_date, :end_date )
|
12
12
|
|
13
13
|
|
14
|
-
def self.
|
15
|
-
|
16
|
-
|
14
|
+
def self.read( path )
|
15
|
+
txt = if path.start_with?( 'http://' ) ||
|
16
|
+
path.start_with?( 'https://' )
|
17
|
+
worker = Fetcher::Worker.new
|
18
|
+
worker.read_utf8!( path )
|
19
|
+
else
|
20
|
+
File.open( path, 'r:utf-8' ).read
|
21
|
+
end
|
17
22
|
|
18
|
-
if
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
23
|
+
parser = if path.end_with?( '.yml') ||
|
24
|
+
path.end_with?( '.yaml')
|
25
|
+
YamlParser.new( txt )
|
26
|
+
else
|
27
|
+
MarkdownParser.new( txt )
|
28
|
+
end
|
29
|
+
parser.parse
|
24
30
|
end
|
25
31
|
|
26
|
-
def self.from_file( path )
|
27
|
-
txt = File.open( path, 'r:utf-8' ).read
|
28
|
-
|
29
|
-
if path.end_with?( '.yml') ||
|
30
|
-
path.end_with?( '.yaml')
|
31
|
-
YamlReader.new( txt )
|
32
|
-
else
|
33
|
-
MarkdownReader.new( txt )
|
34
|
-
end
|
35
|
-
end
|
36
32
|
|
33
|
+
class YamlParser
|
34
|
+
def self.parse( text ) new( text ).parse; end
|
37
35
|
|
38
36
|
|
39
|
-
class YamlReader ## fix/change: rename to YamlParser - why? why not?
|
40
37
|
include LogUtils::Logging
|
41
38
|
|
42
39
|
def initialize( text )
|
43
40
|
@text = text
|
44
41
|
end
|
45
42
|
|
46
|
-
def
|
43
|
+
def parse
|
47
44
|
events = []
|
48
45
|
recs = YAML.load( @text )
|
46
|
+
|
49
47
|
recs.each do |rec|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
48
|
+
if rec.has_key?( 'title' ) ||
|
49
|
+
rec.has_key?( 'link' ) ||
|
50
|
+
rec.has_key?( 'place' )
|
51
|
+
title = rec['title']
|
52
|
+
link = rec['link']
|
53
|
+
place = rec['place']
|
54
|
+
start_date = rec['start_date'] # note: already parsed into a date (NOT string) by yaml parser!!
|
55
|
+
end_date = rec['end_date'] # note: already parsed into a date (NOT string) by yaml parser!!
|
56
|
+
else ## assume "default" format
|
57
|
+
title = rec['name']
|
58
|
+
link = rec['url']
|
59
|
+
place = rec['location']
|
60
|
+
start_date = rec['start'] # note: already parsed into a date (NOT string) by yaml parser!!
|
61
|
+
end_date = rec['end'] # note: already parsed into a date (NOT string) by yaml parser!!
|
62
|
+
end
|
55
63
|
|
56
64
|
event = Event.new( title, link,
|
57
65
|
place,
|
@@ -66,7 +74,10 @@ class YamlReader ## fix/change: rename to YamlParser - why? why not?
|
|
66
74
|
end # class YamlReader
|
67
75
|
|
68
76
|
|
69
|
-
class
|
77
|
+
class MarkdownParser
|
78
|
+
def self.parse( text ) new( text ).parse; end
|
79
|
+
|
80
|
+
|
70
81
|
include LogUtils::Logging
|
71
82
|
|
72
83
|
def initialize( text )
|
@@ -128,7 +139,7 @@ class MarkdownReader ## fix/change: rename to MarkdownParser - why? why not?
|
|
128
139
|
|
129
140
|
|
130
141
|
|
131
|
-
def
|
142
|
+
def parse
|
132
143
|
events = []
|
133
144
|
stack = [] ## header/heading stack; note: last_stack is stack.size; starts w/ 0
|
134
145
|
|
@@ -217,8 +228,8 @@ class MarkdownReader ## fix/change: rename to MarkdownParser - why? why not?
|
|
217
228
|
## Vienna › Austria - why? why not?
|
218
229
|
|
219
230
|
## note: cut of heading 1 (e.g. page title)
|
220
|
-
more_places = stack[1..-1].reverse.map {|it| it[1] }.join(' › ')
|
221
|
-
place = "#{place}
|
231
|
+
more_places = stack[1..-1].reverse.map {|it| it[1] }.join(', ') ## was: join(' › ')
|
232
|
+
place = "#{place}, #{more_places}"
|
222
233
|
logger.debug " place: #{place}"
|
223
234
|
|
224
235
|
|
@@ -278,6 +289,6 @@ def find_title_and_link( line )
|
|
278
289
|
[title,link]
|
279
290
|
end # method find_title_and_link
|
280
291
|
end # class MarkdownReader
|
281
|
-
end # class EventReader
|
282
292
|
|
293
|
+
end # class EventReader
|
283
294
|
end # module EventDb
|