vcardio 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 545dbc5c082b15b136129c2d2d20bdc70c2bef75
4
+ data.tar.gz: 56d160b847e807ee2568c69567feb648c7159fdf
5
+ SHA512:
6
+ metadata.gz: 325fc7cdc351a93e120a95a6a5352ee973f93d80c78fa229b9e117ce4a99c8b1093e248032114368fd087a62024fd7a518e1cee514206c70deaab3fe4daf92bb
7
+ data.tar.gz: 7f268d967c979b97239436b848f1ed83736374214873447690dffbcc4a27df2ac3205ae5750d5bc607982ff074bd3edf177e36c90e6a193233ac33d16e0453c6
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .rbenv*
11
+ .gems
12
+ .ruby-version
13
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,14 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - 2.0.0
6
+ - 2.1.0
7
+ - 2.2.0
8
+ - ruby-head
9
+ - jruby-19mode
10
+ - jruby-head
11
+ matrix:
12
+ allow_failures:
13
+ - rvm: ruby-head
14
+ - rvm: jruby-head
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vcardio.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Anthony Smith
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,87 @@
1
+ # VCardio
2
+
3
+ Build and parse v3 and v4 vCards
4
+
5
+ [![Build Status](https://travis-ci.org/sticksnleaves/vcardio.svg?branch=master)](https://travis-ci.org/sticksnleaves/vcardio)
6
+ [![Code Climate](https://codeclimate.com/github/sticksnleaves/vcardio/badges/gpa.svg)](https://codeclimate.com/github/sticksnleaves/vcardio)
7
+ [![Coverage Status](https://coveralls.io/repos/sticksnleaves/vcardio/badge.svg?branch=master)](https://coveralls.io/r/sticksnleaves/vcardio?branch=master)
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'vcardio'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install vcardio
24
+
25
+ ## Usage
26
+
27
+ ### Create a vCard
28
+
29
+ VCardio comes packed with a powerful and easy to use DSL:
30
+
31
+ ```ruby
32
+ vcard = VCardio::VCard.new('3.0') do
33
+ fn %w(Smith Anthony)
34
+ org 'Sticksnleaves'
35
+ tel '(555) 555-5555', type: 'HOME'
36
+ tel '(555) 555-5556', type: 'WORK'
37
+ item1.gender 'M'
38
+ end
39
+ ```
40
+
41
+ To convert your vCard to a string just call `to_s`:
42
+
43
+ ```ruby
44
+ vcard.to_s # => VCARD:BEGIN
45
+ # VERSION:3.0
46
+ # FN:Smith;Anthony
47
+ # ORG:Sticksnleaves
48
+ # TEL;TYPE=HOME:(555) 555-5555
49
+ # TEL;TYPE=WORK:(555) 555-5556
50
+ # item1.GENDER:M
51
+ # VCARD:END
52
+ ```
53
+
54
+ Or write the vCard to a file:
55
+
56
+ ```ruby
57
+ vcard.to_file('/path/to/file.vcf')
58
+ ```
59
+
60
+ ### Parsing vCards
61
+
62
+ If you already have a vCard and want to manipulate it in Ruby just call
63
+ `VCardio::VCard#parse`.
64
+
65
+ ```ruby
66
+ file = File.open('path/to/file.vcf')
67
+ vcard = VCardio::VCard.parse(file)
68
+
69
+ vcard.fn[0].value # => ['Smith', 'Anthony']
70
+ vcard.org[0].value # => 'Sticksnleaves'
71
+ vcard.tel[0].value # => '(555) 555-5555'
72
+ vcard.tel[1].parameters[0].value # => 'HOME'
73
+ ```
74
+
75
+ ## Development
76
+
77
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
78
+
79
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
80
+
81
+ ## Contributing
82
+
83
+ 1. Fork it ( https://github.com/[my-github-username]/vcardio/fork )
84
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
85
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
86
+ 4. Push to the branch (`git push origin my-new-feature`)
87
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rspec/core'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec) do |spec|
7
+ spec.pattern = FileList['spec/**/*_spec.rb']
8
+ end
9
+
10
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "vcardio"
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
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,64 @@
1
+ module VCardio
2
+ class Builder
3
+ def initialize
4
+ @builders = []
5
+ end
6
+
7
+ def method_missing(method_name, *args)
8
+ return super if respond_to?(method_name)
9
+ builder = PropertyBuilder.new(method_name, args)
10
+ @builders << builder
11
+ builder
12
+ end
13
+
14
+ def properties
15
+ properties = []
16
+
17
+ @builders.each do |builder|
18
+ properties << builder.to_property
19
+ end
20
+
21
+ properties
22
+ end
23
+
24
+ def self.call(&block)
25
+ instance = new
26
+ instance.instance_eval(&block)
27
+ instance
28
+ end
29
+
30
+ class PropertyBuilder
31
+ def initialize(name, args)
32
+ @args = args
33
+ @group = nil
34
+ @name = name
35
+ end
36
+
37
+ def build_parameters(hash)
38
+ hash ||= {}
39
+ parameters = []
40
+
41
+ hash.each do |k, v|
42
+ parameters << VCardio::Parameter.new(k, v)
43
+ end
44
+
45
+ parameters
46
+ end
47
+
48
+ def to_property
49
+ args = @args.clone
50
+ value = args.shift
51
+ parameters = build_parameters(args[0])
52
+
53
+ VCardio::Property.new(@group, @name, parameters, value)
54
+ end
55
+
56
+ def method_missing(method_name, *args)
57
+ @group = @name
58
+ @name = method_name
59
+ @args = args
60
+ self
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,3 @@
1
+ module VCardio
2
+ class Error < StandardError; end
3
+ end
@@ -0,0 +1,34 @@
1
+ module VCardio
2
+ #
3
+ # Name/value parameter pair of a content line definition.
4
+ #
5
+ # Given the content line:
6
+ # `item1.TEL;type=WORK,HOME:+1 617 555 1212`
7
+ #
8
+ # The parameter name will be `type` and value will be `['WORK', 'HOME']`.
9
+ #
10
+ # @attr_reader [String] name
11
+ # @attr_reader [String,Array] value
12
+ #
13
+ class Parameter
14
+ def initialize(name, value)
15
+ @name = name.to_s.upcase
16
+ @value = value
17
+ end
18
+
19
+ attr_reader :name, :value
20
+
21
+ def to_abnf(_spec)
22
+ abnf = @name
23
+ abnf += '='
24
+ abnf += @value.is_a?(Array) ? @value.join(',') : @value.to_s
25
+ abnf
26
+ end
27
+
28
+ def ==(other)
29
+ other.is_a?(VCardio::Parameter) &&
30
+ name == other.name &&
31
+ value == other.value
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,56 @@
1
+ module VCardio
2
+ module Parser
3
+ #
4
+ # @private
5
+ #
6
+ class DocumentParser
7
+ def self.call(vcard)
8
+ document = split_properties(vcard)
9
+
10
+ VCardio::Validator::DocumentValidator.call(document)
11
+
12
+ properties = parse_properties(document)
13
+ version = extract_version(properties)
14
+ properties = clean_properties(properties)
15
+
16
+ VCardio::VCard.new(version, properties)
17
+ end
18
+
19
+ def self.clean_properties(properties)
20
+ properties.each.reject do |property|
21
+ property.name == 'VERSION' ||
22
+ ((property.name == 'BEGIN' ||
23
+ property.name == 'END') &&
24
+ property.value == 'VCARD')
25
+ end
26
+ end
27
+ private_class_method :clean_properties
28
+
29
+ def self.extract_version(properties)
30
+ properties[1].value
31
+ end
32
+ private_class_method :extract_version
33
+
34
+ # Unfold on CRLF + whitespace and split on CRLF or LF.
35
+ def self.split_properties(vcard)
36
+ unfolded_vcard = Manilla.unfold(vcard, "\r\n\s")
37
+ unfolded_vcard.split(/\r\n|\n(?<!\\\\n)/)
38
+ end
39
+ private_class_method :split_properties
40
+
41
+ # Parse document array into property list.
42
+ def self.parse_properties(document)
43
+ properties = []
44
+
45
+ document.each do |line|
46
+ property = VCardio::Parser::LineParser.call(line)
47
+
48
+ properties << property
49
+ end
50
+
51
+ properties
52
+ end
53
+ private_class_method :parse_properties
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,20 @@
1
+ module VCardio
2
+ module Parser
3
+ #
4
+ # @private
5
+ #
6
+ class GroupParser
7
+ def self.call(part)
8
+ separator_index = part.index('.')
9
+
10
+ if separator_index
11
+ group = part[0, separator_index] if separator_index
12
+
13
+ VCardio::Validator::GroupValidator.call(group)
14
+
15
+ group
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ module VCardio
2
+ module Parser
3
+ #
4
+ # @private
5
+ #
6
+ class LineParser
7
+ def self.call(content_line)
8
+ parts = content_line.split(':', 2)
9
+
10
+ group = VCardio::Parser::GroupParser.call(parts[0])
11
+ name = VCardio::Parser::NameParser.call(parts[0])
12
+ params = VCardio::Parser::ParamParser.call(parts[0])
13
+ value = VCardio::Parser::ValueParser.call(parts[1])
14
+
15
+ VCardio::Property.new(group, name, params, value)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,20 @@
1
+ module VCardio
2
+ module Parser
3
+ #
4
+ # @private
5
+ #
6
+ class NameParser
7
+ def self.call(part)
8
+ group_end_index = part.index('.')
9
+ group_sep_index = group_end_index ? group_end_index + 1 : 0
10
+ line_end_index = (part.index(';') || part.length) - group_sep_index
11
+
12
+ name = part[group_sep_index, line_end_index]
13
+
14
+ VCardio::Validator::NameValidator.call(name)
15
+
16
+ name
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,51 @@
1
+ module VCardio
2
+ module Parser
3
+ #
4
+ # @private
5
+ #
6
+ class ParamParser
7
+ def self.call(part)
8
+ values = []
9
+ name_end_index = part.index(';')
10
+
11
+ if name_end_index
12
+ params = part[name_end_index + 1, part.length].split(';', -1)
13
+
14
+ values = compose_values(params)
15
+ end
16
+
17
+ values
18
+ end
19
+
20
+ #
21
+ # Join param name/value pair into an array. Strip out DQUOTE. Split param
22
+ # value if comma separated.
23
+ #
24
+ def self.compose_param(name, value)
25
+ value = value.gsub(/"/, '')
26
+ value = value.split(',') if value.index(',')
27
+
28
+ VCardio::Parameter.new(name, value)
29
+ end
30
+ private_class_method :compose_param
31
+
32
+ #
33
+ # Join all param name/value pairs into a multi-dimensional array.
34
+ #
35
+ def self.compose_values(params)
36
+ values = []
37
+
38
+ params.each do |param|
39
+ parts = param.split('=', 2)
40
+
41
+ VCardio::Validator::ParamNameValidator.call(parts[0])
42
+
43
+ values << compose_param(parts[0], parts[1])
44
+ end
45
+
46
+ values
47
+ end
48
+ private_class_method :compose_values
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,13 @@
1
+ module VCardio
2
+ module Parser
3
+ #
4
+ # @private
5
+ #
6
+ class ValueParser
7
+ def self.call(part)
8
+ value = part.split(/;(?<!\\;)/, -1)
9
+ value.length > 1 ? value : value[0]
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,46 @@
1
+ module VCardio
2
+ #
3
+ # Content line definition and value.
4
+ #
5
+ # @attr_reader [String] group
6
+ # @attr_reader [String] name
7
+ # @attr_reader [Array<VCardio::Parameter>] parameters
8
+ # @attr_reader [String,Array] value
9
+ #
10
+ class Property
11
+ def initialize(group, name, parameters, value)
12
+ @group = group ? group.to_s : nil
13
+ @name = name.to_s.upcase
14
+ @parameters = parameters || []
15
+ @value = value
16
+ end
17
+
18
+ attr_reader :group, :name, :parameters, :value
19
+
20
+ def to_abnf(spec)
21
+ abnf = @group || ''
22
+ parameters = []
23
+ abnf += '.' if @group
24
+ abnf += @name
25
+
26
+ @parameters.each do |parameter|
27
+ parameters << parameter.to_abnf(spec)
28
+ end
29
+
30
+ abnf += parameters.size > 0 ? ';' : ''
31
+ abnf += parameters.join(';')
32
+ abnf += ':'
33
+ abnf += @value.is_a?(Array) ? @value.join(';') : @value.to_s
34
+
35
+ abnf
36
+ end
37
+
38
+ def ==(other)
39
+ other.is_a?(VCardio::Property) &&
40
+ other.group == group &&
41
+ other.name == name &&
42
+ other.parameters == parameters &&
43
+ other.value == value
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,34 @@
1
+ module VCardio
2
+ module Validator
3
+ #
4
+ # @private
5
+ #
6
+ class DocumentValidator
7
+ def self.call(document)
8
+ lines = document.reject(&:empty?)
9
+
10
+ begin_vcard = false
11
+ end_vcard = false
12
+ fn = false
13
+ version = false
14
+
15
+ lines.each_with_index do |line, i|
16
+ if i == 0 && /\ABEGIN:VCARD\z/.match(line)
17
+ begin_vcard = true
18
+ elsif (i == lines.size - 1) && /\AEND:VCARD\z/.match(line)
19
+ end_vcard = true
20
+ elsif /\AFN:/.match(line)
21
+ fn = true
22
+ elsif i == 1 && /\AVERSION:(3.0|4.0)\z/.match(line)
23
+ version = true
24
+ end
25
+ end
26
+
27
+ fail(VCardio::Error, 'Invalid vCard: First line must be BEGIN:VCARD') unless begin_vcard
28
+ fail(VCardio::Error, 'Invalid vCard: Last line must be END:VCARD') unless end_vcard
29
+ fail(VCardio::Error, 'Invalid vCard: Second line must be VERSION with value 3.0 or 4.0') unless version
30
+ fail(VCardio::Error, 'Invalid vCard: Must contain the FN property') unless fn
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,17 @@
1
+ module VCardio
2
+ module Validator
3
+ #
4
+ # Group definition:
5
+ # `1*(ALPHA / DIGIT / "-")`
6
+ #
7
+ # @private
8
+ #
9
+ class GroupValidator
10
+ def self.call(group)
11
+ if /\A[A-Za-z\d-]*\z/.match(group).nil?
12
+ fail VCardio::Error, "Invalid group: #{group}"
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,28 @@
1
+ module VCardio
2
+ module Validator
3
+ #
4
+ # Name definition:
5
+ # "SOURCE" / "KIND" / "FN" / "N" / "NICKNAME"
6
+ # / "PHOTO" / "BDAY" / "ANNIVERSARY" / "GENDER" / "ADR" / "TEL"
7
+ # / "EMAIL" / "IMPP" / "LANG" / "TZ" / "GEO" / "TITLE" / "ROLE"
8
+ # / "LOGO" / "ORG" / "MEMBER" / "RELATED" / "CATEGORIES"
9
+ # / "NOTE" / "PRODID" / "REV" / "SOUND" / "UID" / "CLIENTPIDMAP"
10
+ # / "URL" / "KEY" / "FBURL" / "CALADRURI" / "CALURI" / "XML"
11
+ # / iana-token / x-name
12
+ #
13
+ # Although the name definition has a long list of possible values the
14
+ # `iana-token` pattern is the least common denominator. It basically allows
15
+ # `name` to match anything that follows the `1*(ALPHA / DIGIT / "-")`
16
+ # pattern. Therefore that's all we validate against.
17
+ #
18
+ # @private
19
+ #
20
+ class NameValidator
21
+ def self.call(name)
22
+ if /\A[A-Za-z\d-]*\z/.match(name).nil?
23
+ fail VCardio::Error, "Invalid name: #{name}"
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,25 @@
1
+ module VCardio
2
+ module Validator
3
+ #
4
+ # Param name definition:
5
+ # language-param / value-param / pref-param / pid-param
6
+ # / type-param / geo-parameter / tz-parameter / sort-as-param
7
+ # / calscale-param / any-param
8
+ #
9
+ # Although the param name definition has a list of possible values the
10
+ # `any-param` pattern (which includes the `iana-token`) pattern is the least
11
+ # common denominator. It basically allows param name to match anything that
12
+ # follows the `1*(ALPHA / DIGIT / "-")` pattern. Therefore that's all we
13
+ # validate against.
14
+ #
15
+ # @private
16
+ #
17
+ class ParamNameValidator
18
+ def self.call(param_name)
19
+ if /\A[A-Za-z\d-]*\z/.match(param_name).nil?
20
+ fail VCardio::Error, "Invalid parameter name: #{param_name}"
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,80 @@
1
+ module VCardio
2
+ class VCard
3
+ def initialize(version = '3.0', properties = [], &block)
4
+ @properties = properties
5
+ @version = version
6
+
7
+ builder(&block) if block_given?
8
+ end
9
+
10
+ attr_reader :properties, :version
11
+
12
+ def get(property_name)
13
+ @properties.select { |p| p.name == property_name.to_s.upcase }
14
+ end
15
+
16
+ def separator
17
+ if spec == :rfc2426
18
+ "\n"
19
+ elsif spec == :rfc6350
20
+ "\r\n"
21
+ end
22
+ end
23
+
24
+ def spec
25
+ if @version == '3.0'
26
+ :rfc2426
27
+ elsif @version == '4.0'
28
+ :rfc6350
29
+ end
30
+ end
31
+
32
+ def to_abnf
33
+ abnf = []
34
+ abnf << 'BEGIN:VCARD'
35
+ abnf << "VERSION:#{version}"
36
+
37
+ @properties.each do |property|
38
+ abnf << "#{Manilla.fold(property.to_abnf(spec), 75, "\r\n\s")}"
39
+ end
40
+
41
+ abnf << 'END:VCARD'
42
+
43
+ abnf.join(separator)
44
+ end
45
+ alias_method :to_s, :to_abnf
46
+
47
+ def to_file(path)
48
+ File.write(path, to_abnf)
49
+ end
50
+
51
+ def ==(other)
52
+ other.is_a?(VCardio::VCard) &&
53
+ other.properties == properties &&
54
+ other.version == version
55
+ end
56
+
57
+ def method_missing(method_name, *args, &block)
58
+ return super if respond_to?(method_name)
59
+ get(method_name)
60
+ end
61
+
62
+ def self.parse(file)
63
+ if file.is_a?(String)
64
+ VCardio::Parser::DocumentParser.call(file)
65
+ elsif file.is_a?(File)
66
+ VCardio::Parser::DocumentParser.call(file.read)
67
+ else
68
+ fail(VCardio::Error, 'Could not parse. Expecting string or file.')
69
+ end
70
+ end
71
+
72
+ private
73
+
74
+ def builder(&block)
75
+ builder = VCardio::Builder.call(&block)
76
+
77
+ @properties.concat(builder.properties)
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,3 @@
1
+ module VCardio
2
+ VERSION = "0.1.0"
3
+ end
data/lib/vcardio.rb ADDED
@@ -0,0 +1,22 @@
1
+ require 'manilla'
2
+
3
+ require 'vcardio/builder'
4
+ require 'vcardio/error'
5
+ require 'vcardio/parameter'
6
+ require 'vcardio/property'
7
+ require 'vcardio/vcard'
8
+ require 'vcardio/parser/document_parser'
9
+ require 'vcardio/parser/group_parser'
10
+ require 'vcardio/parser/line_parser'
11
+ require 'vcardio/parser/name_parser'
12
+ require 'vcardio/parser/param_parser'
13
+ require 'vcardio/parser/value_parser'
14
+ require 'vcardio/validator/document_validator'
15
+ require 'vcardio/validator/group_validator'
16
+ require 'vcardio/validator/name_validator'
17
+ require 'vcardio/validator/param_name_validator'
18
+ require 'vcardio/version'
19
+
20
+ module VCardio
21
+ # Your code goes here...
22
+ end
data/vcardio.gemspec ADDED
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vcardio/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'vcardio'
8
+ spec.version = VCardio::VERSION
9
+ spec.authors = ['Anthony Smith']
10
+ spec.email = ['anthony@sticksnleaves.com']
11
+
12
+ spec.summary = 'vCard builder and parser for Ruby'
13
+ spec.description = 'RFC 6350 compliant implementation of vCard for Ruby'
14
+ spec.homepage = 'https://github.com/sticksnleaves/vcardio.git'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = (
18
+ `git ls-files -z`.split("\x0").reject do |f|
19
+ f.match(/^(test|spec|features)\//)
20
+ end
21
+ )
22
+
23
+ spec.bindir = 'exe'
24
+ spec.executables = spec.files.grep(/^exe\//) { |f| File.basename(f) }
25
+ spec.require_paths = ['lib']
26
+
27
+ spec.add_dependency 'manilla', '~> 1.0.0'
28
+
29
+ spec.add_development_dependency 'bundler'
30
+ spec.add_development_dependency 'coveralls'
31
+ spec.add_development_dependency 'rake'
32
+ spec.add_development_dependency 'rspec'
33
+ spec.add_development_dependency 'simplecov'
34
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vcardio
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Anthony Smith
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-04-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: manilla
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: coveralls
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
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
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: RFC 6350 compliant implementation of vCard for Ruby
98
+ email:
99
+ - anthony@sticksnleaves.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - CODE_OF_CONDUCT.md
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - lib/vcardio.rb
115
+ - lib/vcardio/builder.rb
116
+ - lib/vcardio/error.rb
117
+ - lib/vcardio/parameter.rb
118
+ - lib/vcardio/parser/document_parser.rb
119
+ - lib/vcardio/parser/group_parser.rb
120
+ - lib/vcardio/parser/line_parser.rb
121
+ - lib/vcardio/parser/name_parser.rb
122
+ - lib/vcardio/parser/param_parser.rb
123
+ - lib/vcardio/parser/value_parser.rb
124
+ - lib/vcardio/property.rb
125
+ - lib/vcardio/validator/document_validator.rb
126
+ - lib/vcardio/validator/group_validator.rb
127
+ - lib/vcardio/validator/name_validator.rb
128
+ - lib/vcardio/validator/param_name_validator.rb
129
+ - lib/vcardio/vcard.rb
130
+ - lib/vcardio/version.rb
131
+ - vcardio.gemspec
132
+ homepage: https://github.com/sticksnleaves/vcardio.git
133
+ licenses:
134
+ - MIT
135
+ metadata: {}
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubyforge_project:
152
+ rubygems_version: 2.4.5
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: vCard builder and parser for Ruby
156
+ test_files: []