ruby-vobject 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +94 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/vobject.rb +182 -0
- data/lib/vobject/component.rb +75 -0
- data/lib/vobject/property.rb +83 -0
- data/lib/vobject/version.rb +3 -0
- data/ruby-vobject.gemspec +28 -0
- metadata +117 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8eacb24dd83246f0c7c6c471e35006a873e16375
|
4
|
+
data.tar.gz: 672b1adf63c60ef661c3813f28f13a6840a9f207
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 53a78d422fd94f646b59ce856c1774b8dccb564982bc6c28093838c57a3bc9e709e52ae88e8af03dad131706b75bc51ef461218435ef5b3c71e4986f224780e1
|
7
|
+
data.tar.gz: c38a88f5a898354916c9f307da1cb0be4ff884a3fa27a5e60faa37a4f0bfffa45bd4ec688620a759d6956b619b3cee85f34a5e91e2bdce47f70cd3360ef599cc
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at peter.tam@ribose.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Peter Tam
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
# Vobject
|
2
|
+
|
3
|
+
The main purpose of the gem is to parse vobject formatted text into a ruby
|
4
|
+
hash format. Currently there are two possiblities of vobjects, namely
|
5
|
+
iCalendar (https://tools.ietf.org/html/rfc5545) and vCard
|
6
|
+
(https://tools.ietf.org/html/rfc6350). There are only a few differences
|
7
|
+
between the iCalendar and vCard format. Only vCard supports grouping
|
8
|
+
feature, and currently vCard does not have any sub-object supported.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'ruby-vobject'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install ruby-vobject
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
Vobject.parse("<ics/vcf file>")
|
29
|
+
|
30
|
+
Example:
|
31
|
+
|
32
|
+
A sample ics file (in spec/examples/example2.ics):
|
33
|
+
|
34
|
+
```
|
35
|
+
BEGIN:VCALENDAR
|
36
|
+
VERSION:2.0
|
37
|
+
PRODID:-//ABC Corporation//NONSGML My Product//EN
|
38
|
+
BEGIN:VTODO
|
39
|
+
DTSTAMP:19980130T134500Z
|
40
|
+
SEQUENCE:2
|
41
|
+
UID:uid4@example.com
|
42
|
+
ORGANIZER:mailto:unclesam@example.com
|
43
|
+
ATTENDEE;PARTSTAT=ACCEPTED:mailto:jqpublic@example.com
|
44
|
+
DUE:19980415T000000
|
45
|
+
STATUS:NEEDS-ACTION
|
46
|
+
SUMMARY:Submit Income Taxes
|
47
|
+
BEGIN:VALARM
|
48
|
+
ACTION:AUDIO
|
49
|
+
TRIGGER:19980403T120000Z
|
50
|
+
ATTACH;FMTTYPE=audio/basic:http://example.com/pub/audio-
|
51
|
+
files/ssbanner.aud
|
52
|
+
REPEAT:4
|
53
|
+
DURATION:PT1H
|
54
|
+
END:VALARM
|
55
|
+
END:VTODO
|
56
|
+
END:VCALENDAR
|
57
|
+
```
|
58
|
+
|
59
|
+
Parse the ics file into Ruby hash format:
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
require 'vobject'
|
63
|
+
|
64
|
+
ics = File.read "spec/examples/example2.ics"
|
65
|
+
Vobject.parse(ics)
|
66
|
+
|
67
|
+
=> {:VCALENDAR=>[{:VERSION=>{:value=>"2.0"}}, {:PRODID=>{:value=>"-//ABC Corporation//NONSGML My Product//EN"}}, {:VTODO=>[{:DTSTAMP=>{:value=>"19980130T134500Z"}}, {:SEQUENCE=>{:value=>"2"}}, {:UID=>{:value=>"uid4@example.com"}}, {:ORGANIZER=>{:value=>"mailto:unclesam@example.com"}}, {:ATTENDEE=>{:params=>{:PARTSTAT=>"ACCEPTED"}, :value=>"mailto:jqpublic@example.com"}}, {:DUE=>{:value=>"19980415T000000"}}, {:STATUS=>{:value=>"NEEDS-ACTION"}}, {:SUMMARY=>{:value=>"Submit Income Taxes"}}, {:VALARM=>[{:ACTION=>{:value=>"AUDIO"}}, {:TRIGGER=>{:value=>"19980403T120000Z"}}, {:ATTACH=>{:params=>{:FMTTYPE=>"audio/basic"}, :value=>"http://example.com/pub/audio-files/ssbanner.aud"}}, {:REPEAT=>{:value=>"4"}}, {:DURATION=>{:value=>"PT1H"}}]}]}]}
|
68
|
+
```
|
69
|
+
|
70
|
+
Running spec:
|
71
|
+
bundle exec rspec
|
72
|
+
|
73
|
+
|
74
|
+
## Development
|
75
|
+
|
76
|
+
Currently the parser is written by regular expression. However, it is
|
77
|
+
hard to maintain. A better approach will be using some grammar parser
|
78
|
+
library, such as treetop (https://rubygems.org/gems/treetop/versions/1.6.8).
|
79
|
+
|
80
|
+
Some really simple specs have been written. Please make sure they still
|
81
|
+
pass after migrating into the grammar parser approach. Also, some other
|
82
|
+
specs such as some special characters as stated in RFC 5545 and 6350
|
83
|
+
should be tested as well.
|
84
|
+
|
85
|
+
|
86
|
+
## Contributing
|
87
|
+
|
88
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/riboseinc/ruby-vobject. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
89
|
+
|
90
|
+
|
91
|
+
## License
|
92
|
+
|
93
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
94
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "vobject"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/vobject.rb
ADDED
@@ -0,0 +1,182 @@
|
|
1
|
+
require "vobject/version"
|
2
|
+
|
3
|
+
module Vobject
|
4
|
+
|
5
|
+
module Rules
|
6
|
+
|
7
|
+
module ABNF
|
8
|
+
IANAToken = '[a-zA-Z\d\-]+?'
|
9
|
+
Cr = "\u000d"
|
10
|
+
Lf = "\u000a"
|
11
|
+
Crlf = "(#{Cr}|#{Lf})"
|
12
|
+
Utf8_tail = '[\u0080-\u00bf]'
|
13
|
+
Utf8_2 = '([\u00c2-\u00df]|' + "#{Utf8_tail})"
|
14
|
+
Utf8_3 = '([\u00e0\u00a0-\u00bf\u00e1-\u00ec\u00ed\u0080-\u009f\u00ee-\u00ef]|' + "#{Utf8_tail})"
|
15
|
+
Utf8_4 = '([\u00f0\u0090-\u00bf\u00f1-\u00f3\u00f4\u0080-\u008f]|' + "#{Utf8_tail})"
|
16
|
+
Wsp = '[ \t]'
|
17
|
+
VChar = '[\u0021-\u007e]'
|
18
|
+
NonASCII = "(#{Utf8_2}|#{Utf8_3}|#{Utf8_4})"
|
19
|
+
QSafeChar = "(#{Wsp}|" + '[!\u0023-\u007e]' + "|#{NonASCII})"
|
20
|
+
SafeChar = "(#{Wsp}|" + '[!\u0023-\u0039\u003c-\u007e]' + "|#{NonASCII})"
|
21
|
+
ValueChar = "(#{Wsp}|#{VChar}|#{NonASCII})"
|
22
|
+
DQuote = '"'
|
23
|
+
PText = "#{SafeChar}*?"
|
24
|
+
QuotedString = "#{DQuote}(#{QSafeChar}*?)#{DQuote}"
|
25
|
+
XName = "[xX]-#{IANAToken}"
|
26
|
+
Group = IANAToken
|
27
|
+
Name = "(#{XName}|#{IANAToken})"
|
28
|
+
ParamName = "(#{XName}|#{IANAToken})"
|
29
|
+
ParamValue = "(#{PText}|#{QuotedString})"
|
30
|
+
PValueList = "(?<head>#{ParamValue})(?<tail>(,#{ParamValue})*)"
|
31
|
+
Pid = '\d+(\.\d+)*'
|
32
|
+
PidList = "(?<head>#{Pid})(?<tail>(,#{Pid})*)"
|
33
|
+
Param = "(?<pname>#{ParamName})=(?<pvalue>#{PValueList})"
|
34
|
+
Params = "(;(?<phead>#{Param}))(?<ptail>(;#{Param})*)"
|
35
|
+
Value = "#{ValueChar}*?"
|
36
|
+
LineGroup = "((?<group>#{Group})" + '\.' + ")?"
|
37
|
+
Contentline = "#{LineGroup}(?<key>#{Name})(?<params>(#{Params})?):(?<value>#{Value})#{Crlf}"
|
38
|
+
BeginLine = "BEGIN:#{IANAToken}#{Crlf}"
|
39
|
+
VersionLine = "VERSION:#{Value}#{Crlf}"
|
40
|
+
EndLine = "END:#{IANAToken}#{Crlf}"
|
41
|
+
Vobject = "#{BeginLine}#{VersionLine}(#{Contentline})+#{EndLine}"
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
class << self
|
47
|
+
|
48
|
+
def parse(vobject)
|
49
|
+
vobject = unfold(vobject)
|
50
|
+
lines = []
|
51
|
+
rule = "(?<line>#{Rules::ABNF::Contentline})(?<remainder>(#{Rules::ABNF::Contentline})*)"
|
52
|
+
|
53
|
+
parse_for_rule(Rules::ABNF::Vobject, vobject) do |parsed|
|
54
|
+
|
55
|
+
remainder = vobject
|
56
|
+
|
57
|
+
while !remainder.empty?
|
58
|
+
parse_for_rule(rule, remainder) do |remainder_parsed|
|
59
|
+
lines << remainder_parsed[:line]
|
60
|
+
remainder = remainder_parsed[:remainder]
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
parse_lines lines
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def unfold(str)
|
71
|
+
str.gsub(/#{Rules::ABNF::Crlf}#{Rules::ABNF::Wsp}/, '')
|
72
|
+
end
|
73
|
+
|
74
|
+
def parse_lines lines
|
75
|
+
lines.each_with_index.reduce([]) do |hash_stack, (line, i)|
|
76
|
+
prop = parse_line(line)
|
77
|
+
|
78
|
+
if prop.has_key?(:BEGIN)
|
79
|
+
comp = prop[:BEGIN][:value].to_sym
|
80
|
+
hash = { comp => [] }
|
81
|
+
next hash_stack << hash
|
82
|
+
end
|
83
|
+
|
84
|
+
if prop.has_key?(:END)
|
85
|
+
hash = hash_stack.pop
|
86
|
+
comp = hash.keys.first
|
87
|
+
|
88
|
+
raise_invalid_parsing if comp != prop[:END][:value].to_sym
|
89
|
+
|
90
|
+
prev_hash = hash_stack.last
|
91
|
+
|
92
|
+
raise_invalid_parsing if !prev_hash && i != lines.length - 1
|
93
|
+
|
94
|
+
return hash unless prev_hash
|
95
|
+
|
96
|
+
prev_hash[prev_hash.keys.first] << hash
|
97
|
+
|
98
|
+
next hash_stack
|
99
|
+
end
|
100
|
+
|
101
|
+
prev_hash = hash_stack.last
|
102
|
+
|
103
|
+
prev_hash[prev_hash.keys.first] << prop
|
104
|
+
hash_stack
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def parse_line(line)
|
109
|
+
parse_for_rule(Rules::ABNF::Contentline, unfold(line)) do |parsed|
|
110
|
+
key = parsed[:key].to_sym
|
111
|
+
|
112
|
+
group = parsed[:group]
|
113
|
+
params = parse_params(parsed[:params])
|
114
|
+
value = parsed[:value]
|
115
|
+
|
116
|
+
hash = { key => {} }
|
117
|
+
hash[key][:group] = group if group
|
118
|
+
hash[key][:params] = params if !params.empty?
|
119
|
+
hash[key][:value] = value
|
120
|
+
|
121
|
+
hash
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def parse_params(params_str)
|
126
|
+
params = {}
|
127
|
+
|
128
|
+
while !params_str.empty?
|
129
|
+
parse_for_rule(Rules::ABNF::Params, params_str) do |parsed|
|
130
|
+
|
131
|
+
parse_for_rule(Rules::ABNF::Param, parsed[:phead]) do |param_parsed|
|
132
|
+
pname = param_parsed[:pname].to_sym
|
133
|
+
pvalue = param_parsed[:pvalue].sub(
|
134
|
+
Regexp.new("^#{Rules::ABNF::QuotedString}$"),
|
135
|
+
'\1'
|
136
|
+
)
|
137
|
+
|
138
|
+
pvalue.gsub!(/\\n/, "\n")
|
139
|
+
|
140
|
+
params[pname] = if params[pname]
|
141
|
+
"#{params[pname]},#{pvalue}"
|
142
|
+
else
|
143
|
+
pvalue
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
params_str = parsed[:ptail]
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
params
|
152
|
+
end
|
153
|
+
|
154
|
+
#Method: parse_for_rule
|
155
|
+
#Parameter: String containing the regular expression, String to be parsed
|
156
|
+
#and optional block to indicate whether to yield the resulting hash
|
157
|
+
#Return: a hash with keys indicating their regex names
|
158
|
+
def parse_for_rule(rule, str, &block)
|
159
|
+
matched = /\A#{rule}\Z/.match(str)
|
160
|
+
|
161
|
+
raise_invalid_parsing unless matched
|
162
|
+
|
163
|
+
parsed = matched.names.reduce({}) do |parsed_hash, name|
|
164
|
+
#can we reduce memory consumption by only creating Keys whose value is not nil?
|
165
|
+
parsed_hash[name.to_sym] = matched[name.to_sym] if matched[name.to_sym]
|
166
|
+
#parsed_hash[name.to_sym] = matched[name.to_sym]
|
167
|
+
parsed_hash
|
168
|
+
end
|
169
|
+
|
170
|
+
return yield(parsed) if block
|
171
|
+
|
172
|
+
parsed
|
173
|
+
end
|
174
|
+
|
175
|
+
def raise_invalid_parsing
|
176
|
+
raise "VObject parse failed"
|
177
|
+
end
|
178
|
+
|
179
|
+
end
|
180
|
+
|
181
|
+
end
|
182
|
+
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'vobject'
|
2
|
+
require 'vobject/property'
|
3
|
+
|
4
|
+
class Vobject::Component
|
5
|
+
|
6
|
+
attr_accessor :comp_name, :children
|
7
|
+
|
8
|
+
class << self
|
9
|
+
|
10
|
+
def parse(vcf)
|
11
|
+
hash = Vobject.parse(vcf)
|
12
|
+
comp_name = hash.keys.first
|
13
|
+
|
14
|
+
self.new comp_name, hash[comp_name]
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def raise_invalid_parsing
|
20
|
+
raise "Vobject component parse failed"
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize key, cs
|
26
|
+
self.comp_name = key
|
27
|
+
|
28
|
+
raise_invalid_initialization if key != name
|
29
|
+
|
30
|
+
self.children = cs.map do |c|
|
31
|
+
key = c.keys.first
|
32
|
+
val = c[key]
|
33
|
+
|
34
|
+
cc = child_class(key, val)
|
35
|
+
cc.new key, val
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_s
|
40
|
+
s = "BEGIN:#{name}\n"
|
41
|
+
|
42
|
+
children.each do |c|
|
43
|
+
s << c.to_s
|
44
|
+
end
|
45
|
+
|
46
|
+
s << "END:#{name}\n"
|
47
|
+
|
48
|
+
s
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def name
|
54
|
+
comp_name
|
55
|
+
end
|
56
|
+
|
57
|
+
def child_class key, val
|
58
|
+
base_class = val.is_a?(Array) ? component_base_class : property_base_class
|
59
|
+
camelized_key = key.to_s.downcase.split("_").map(&:capitalize).join("")
|
60
|
+
base_class.const_get(camelized_key) rescue base_class
|
61
|
+
end
|
62
|
+
|
63
|
+
def property_base_class
|
64
|
+
Vobject::Property
|
65
|
+
end
|
66
|
+
|
67
|
+
def component_base_class
|
68
|
+
Vobject::Component
|
69
|
+
end
|
70
|
+
|
71
|
+
def raise_invalid_initialization
|
72
|
+
raise "vObject component initialization failed"
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module Vobject
|
2
|
+
|
3
|
+
class Property
|
4
|
+
|
5
|
+
MAX_LINE_WIDTH = 75
|
6
|
+
|
7
|
+
attr_accessor :group, :prop_name, :params, :value
|
8
|
+
|
9
|
+
def initialize key, options
|
10
|
+
self.group = options[:group]
|
11
|
+
self.prop_name = key
|
12
|
+
self.params = options[:params]
|
13
|
+
self.value = parse_value(options[:value])
|
14
|
+
|
15
|
+
raise_invalid_initialization if key != name
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_s
|
19
|
+
line = group ? "#{group}." : ""
|
20
|
+
line << "#{name}"
|
21
|
+
|
22
|
+
(params || {}).each do |pname, pvalue|
|
23
|
+
pvalue.to_s.gsub!(/\n/, '\n')
|
24
|
+
|
25
|
+
line << ";#{pname}=#{pvalue}"
|
26
|
+
end
|
27
|
+
|
28
|
+
line << ":#{value}"
|
29
|
+
|
30
|
+
line = fold_line(line) << "\n"
|
31
|
+
|
32
|
+
line
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def name
|
38
|
+
prop_name
|
39
|
+
end
|
40
|
+
|
41
|
+
def parse_value value
|
42
|
+
parse_method = :"parse_#{value_type}_value"
|
43
|
+
parse_method = respond_to?(parse_method, true) ? parse_method : :parse_text_value
|
44
|
+
send(parse_method, value)
|
45
|
+
end
|
46
|
+
|
47
|
+
def parse_text_value value
|
48
|
+
value
|
49
|
+
end
|
50
|
+
|
51
|
+
def value_type
|
52
|
+
(params || {})[:VALUE] || default_value_type
|
53
|
+
end
|
54
|
+
|
55
|
+
def default_value_type
|
56
|
+
"text"
|
57
|
+
end
|
58
|
+
|
59
|
+
def raise_invalid_initialization
|
60
|
+
raise "vObject property initialization failed"
|
61
|
+
end
|
62
|
+
|
63
|
+
# This implements the line folding as specified in
|
64
|
+
# http://tools.ietf.org/html/rfc6350#section-3.2
|
65
|
+
#
|
66
|
+
# NOTE: the "line" here is not including the trailing \n
|
67
|
+
def fold_line(line)
|
68
|
+
folded_line = line[0, MAX_LINE_WIDTH]
|
69
|
+
remainder_line = line[MAX_LINE_WIDTH, line.length - MAX_LINE_WIDTH] || ''
|
70
|
+
|
71
|
+
max_width = MAX_LINE_WIDTH - 1
|
72
|
+
|
73
|
+
for i in 0..((remainder_line.length - 1) / max_width)
|
74
|
+
folded_line << "\n "
|
75
|
+
folded_line << remainder_line[i * max_width, max_width]
|
76
|
+
end
|
77
|
+
|
78
|
+
folded_line
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'vobject/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ruby-vobject"
|
8
|
+
spec.version = Vobject::VERSION
|
9
|
+
spec.authors = ["Peter Tam"]
|
10
|
+
spec.email = ["peter.tam@ribose.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{The main purpose of the gem is to parse vobject formatted text into a ruby
|
13
|
+
hash format. Currently there are two possiblities of vobjects, namely
|
14
|
+
iCalendar (https://tools.ietf.org/html/rfc5545) and vCard
|
15
|
+
(https://tools.ietf.org/html/rfc6350).}
|
16
|
+
spec.homepage = "https://www.ribose.com"
|
17
|
+
spec.license = "MIT"
|
18
|
+
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
27
|
+
spec.add_development_dependency "rspec-json_expectations"
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby-vobject
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Peter Tam
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-07-01 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.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
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.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
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.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec-json_expectations
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- peter.tam@ribose.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- CODE_OF_CONDUCT.md
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- lib/vobject.rb
|
87
|
+
- lib/vobject/component.rb
|
88
|
+
- lib/vobject/property.rb
|
89
|
+
- lib/vobject/version.rb
|
90
|
+
- ruby-vobject.gemspec
|
91
|
+
homepage: https://www.ribose.com
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.5.2
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: The main purpose of the gem is to parse vobject formatted text into a ruby
|
115
|
+
hash format. Currently there are two possiblities of vobjects, namely iCalendar
|
116
|
+
(https://tools.ietf.org/html/rfc5545) and vCard (https://tools.ietf.org/html/rfc6350).
|
117
|
+
test_files: []
|