forward-calendar 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/forward-calendar.gemspec +2 -2
- data/lib/forward_calendar.rb +5 -5
- data/lib/forward_calendar/address.rb +15 -0
- data/lib/forward_calendar/event.rb +25 -0
- data/lib/forward_calendar/forward_calendar.rb +24 -8
- data/lib/forward_calendar/helper/normalized_string.rb +17 -0
- data/lib/forward_calendar/location.rb +25 -0
- data/lib/forward_calendar/location_end_time.rb +11 -0
- data/lib/forward_calendar/location_start_time.rb +11 -0
- data/lib/forward_calendar/location_time.rb +13 -0
- data/lib/forward_calendar/updated.rb +1 -1
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 862009b8848681c1e0194d4542a9d3e9c02d0ec5
|
4
|
+
data.tar.gz: 55be0c0aa4df8e86a278365f9955123e9564c48d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f42238e2c8f2edad3b68f61f44714045fac80474ab5a83cbd563c19f5b520e30ae1758317aeab5a029fadf59d42b1dcb150d8084063c731f692a65322afef9a3
|
7
|
+
data.tar.gz: 99a34126b47f19d2034e31613849899eb8c9316d0e40eb3794ceca4296d43808270f3906157fa5754b40ebef1898331905c1c05010a86f461eb3f4ab900bb562
|
data/forward-calendar.gemspec
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'forward-calendar'
|
5
|
-
s.version = '0.0
|
6
|
-
s.date = '2017-
|
5
|
+
s.version = '0.1.0'
|
6
|
+
s.date = '2017-12-07'
|
7
7
|
s.summary = 'Forward Calendar XML parser'
|
8
8
|
s.description = 'Parser for Forward Calendar XML files'
|
9
9
|
s.homepage = 'https://github.com/AlphaExchange/forward-calendar-rb'
|
data/lib/forward_calendar.rb
CHANGED
@@ -3,12 +3,12 @@
|
|
3
3
|
require_relative './forward_calendar/forward_calendar'
|
4
4
|
|
5
5
|
module ForwardCalendar
|
6
|
-
def self.
|
7
|
-
ForwardCalendar.
|
6
|
+
def self.parser(file_content)
|
7
|
+
ForwardCalendar.new(file_content)
|
8
8
|
end
|
9
9
|
|
10
|
-
def self.
|
11
|
-
xml = File.read(
|
12
|
-
|
10
|
+
def self.parser_from_file(file_path)
|
11
|
+
xml = File.read(file_path)
|
12
|
+
parser(xml)
|
13
13
|
end
|
14
14
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'happymapper'
|
4
|
+
require_relative 'node'
|
5
|
+
|
6
|
+
module ForwardCalendar
|
7
|
+
class Address < Node
|
8
|
+
include HappyMapper
|
9
|
+
tag 'address'
|
10
|
+
|
11
|
+
element :city, String, tag: 'city'
|
12
|
+
element :state, String, tag: 'state'
|
13
|
+
element :country, String, tag: 'country'
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'happymapper'
|
4
|
+
require_relative 'node'
|
5
|
+
require_relative './location'
|
6
|
+
require_relative './helper/normalized_string'
|
7
|
+
|
8
|
+
module ForwardCalendar
|
9
|
+
class Event < Node
|
10
|
+
include HappyMapper
|
11
|
+
tag 'event'
|
12
|
+
|
13
|
+
has_many :locations, Location, tag: 'eventLocation', xpath: './eventLocations'
|
14
|
+
|
15
|
+
element :id, Integer, tag: 'eventID'
|
16
|
+
element :type, Helper::NormalizedString, tag: 'eventType'
|
17
|
+
element :title, String, tag: 'eventTitle'
|
18
|
+
element :status, Helper::NormalizedString, tag: 'eventStatus'
|
19
|
+
element :broker, String, tag: 'broker'
|
20
|
+
element :description, String, tag: 'eventDescription'
|
21
|
+
element :start, Date, tag: 'start'
|
22
|
+
element :end, Date, tag: 'end'
|
23
|
+
element :url, String, tag: 'URL'
|
24
|
+
end
|
25
|
+
end
|
@@ -1,19 +1,35 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'happymapper'
|
4
3
|
require 'nokogiri'
|
5
|
-
require_relative './
|
4
|
+
require_relative './event'
|
6
5
|
require_relative './updated'
|
7
6
|
|
8
7
|
module ForwardCalendar
|
9
|
-
class ForwardCalendar
|
10
|
-
|
11
|
-
|
8
|
+
class ForwardCalendar
|
9
|
+
def initialize(file)
|
10
|
+
@file = file
|
11
|
+
end
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
##
|
14
|
+
# Immidiately returns the Updated element as soon as it gets parsed.
|
15
|
+
# (Avoids the complete traverse of the file if the Updated element is set
|
16
|
+
# at the beggining of the file)
|
17
|
+
#
|
18
|
+
def updated
|
19
|
+
Nokogiri::XML::Reader(@file).each do |node|
|
20
|
+
next unless node.name == 'updated' && node.node_type == Nokogiri::XML::Reader::TYPE_ELEMENT
|
21
|
+
return Updated.parse(Nokogiri::XML(node.outer_xml))
|
22
|
+
end
|
15
23
|
end
|
16
24
|
|
17
|
-
|
25
|
+
##
|
26
|
+
# Yields each Event from the Snapshot file being parsed.
|
27
|
+
#
|
28
|
+
def each_event
|
29
|
+
Nokogiri::XML::Reader(@file).each do |node|
|
30
|
+
next unless node.name == 'event' && node.node_type == Nokogiri::XML::Reader::TYPE_ELEMENT
|
31
|
+
yield Event.parse(Nokogiri::XML(node.outer_xml))
|
32
|
+
end
|
33
|
+
end
|
18
34
|
end
|
19
35
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'happymapper'
|
3
|
+
require 'active_support/core_ext/string'
|
4
|
+
|
5
|
+
module ForwardCalendar
|
6
|
+
module Helper
|
7
|
+
class NormalizedString
|
8
|
+
def self.parse(value)
|
9
|
+
value.to_s.underscore.downcase
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
HappyMapper::SupportedTypes.register_type(ForwardCalendar::Helper::NormalizedString) do |value|
|
16
|
+
ForwardCalendar::Helper::NormalizedString.parse(value)
|
17
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'happymapper'
|
4
|
+
require_relative 'node'
|
5
|
+
require_relative './location_start_time'
|
6
|
+
require_relative './location_end_time'
|
7
|
+
require_relative './address'
|
8
|
+
require_relative './helper/normalized_string'
|
9
|
+
|
10
|
+
module ForwardCalendar
|
11
|
+
class Location < Node
|
12
|
+
include HappyMapper
|
13
|
+
tag 'eventLocation'
|
14
|
+
|
15
|
+
has_one :start_time, LocationStartTime, tag: 'locationStartTime', xpath: './'
|
16
|
+
has_one :end_time, LocationEndTime, tag: 'locationEndTime', xpath: './'
|
17
|
+
has_one :address, Address, tag: 'address', xpath: './'
|
18
|
+
|
19
|
+
element :id, Integer, tag: 'locationID'
|
20
|
+
element :name, String, tag: 'locationEventName'
|
21
|
+
element :status, Helper::NormalizedString, tag: 'locationStatus'
|
22
|
+
element :start_date, Date, tag: 'locationStartDate'
|
23
|
+
element :end_date, Date, tag: 'locationEndDate'
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'happymapper'
|
4
|
+
require_relative 'node'
|
5
|
+
|
6
|
+
module ForwardCalendar
|
7
|
+
class LocationTime < Node
|
8
|
+
include HappyMapper
|
9
|
+
|
10
|
+
element :datetime, Time, tag: 'datetime'
|
11
|
+
element :timezone, String, tag: 'timezone'
|
12
|
+
end
|
13
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: forward-calendar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- João Simões
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -182,7 +182,14 @@ files:
|
|
182
182
|
- forward-calendar.gemspec
|
183
183
|
- lib/forward-calendar.rb
|
184
184
|
- lib/forward_calendar.rb
|
185
|
+
- lib/forward_calendar/address.rb
|
186
|
+
- lib/forward_calendar/event.rb
|
185
187
|
- lib/forward_calendar/forward_calendar.rb
|
188
|
+
- lib/forward_calendar/helper/normalized_string.rb
|
189
|
+
- lib/forward_calendar/location.rb
|
190
|
+
- lib/forward_calendar/location_end_time.rb
|
191
|
+
- lib/forward_calendar/location_start_time.rb
|
192
|
+
- lib/forward_calendar/location_time.rb
|
186
193
|
- lib/forward_calendar/node.rb
|
187
194
|
- lib/forward_calendar/updated.rb
|
188
195
|
- release
|