Skip to content

Commit

Permalink
mandatory typing on normalisation of vcard 4
Browse files Browse the repository at this point in the history
  • Loading branch information
opoudjis committed Sep 23, 2017
1 parent 9471edd commit 0a70d52
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/vobject/vcard/v3_0/propertyvalue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def <=>(another)
def initialize(val)
self.value = val.clone
# val consists of :time && :zone values. If :zone is empty, floating local time (i.e. system local time) is assumed
self.type = "datetimeLocal"
self.type = "datetimelocal"
val[:sec] += (val[:secfrac].to_f / (10**val[:secfrac].length)) if !val[:secfrac].nil? && !val[:secfrac].empty?
value[:time] = if val[:zone].nil? || val[:zone].empty?
::Time.local(val[:year], val[:month], val[:day], val[:hour], val[:min], val[:sec])
Expand Down
20 changes: 20 additions & 0 deletions lib/vobject/vcard/v4_0/property.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,26 @@ def property_base_class
version_class.const_get(:Property)
end


def to_norm_line
line = group ? "#{group}." : ""
line << name.to_s.tr("_", "-").upcase

# add mandatory VALUE param
outparams = params
outparams[:VALUE] = value.type

(outparams || {}).sort.each do |p|
line << ";#{p.to_norm}"
end

line << ":#{value.to_norm}"

line = Vobject::fold_line(line) << "\n"

line
end

def version_class
Vcard::V4_0
end
Expand Down
22 changes: 11 additions & 11 deletions lib/vobject/vcard/v4_0/propertyvalue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def to_hash
class Kindvalue < Text
def initialize(val)
self.value = val
self.type = "kindvalue"
self.type = "text"
end

def to_hash
Expand All @@ -55,7 +55,7 @@ def to_hash
class Lang < Text
def initialize(val)
self.value = val
self.type = "lang"
self.type = "language-tag"
end

def to_hash
Expand All @@ -66,7 +66,7 @@ def to_hash
class Ianatoken < Text
def initialize(val)
self.value = val
self.type = "ianatoken"
self.type = "text"
end

def to_hash
Expand All @@ -92,7 +92,7 @@ def to_s
class Clientpidmap < Text
def initialize(val)
self.value = val
self.type = "clientpidmap"
self.type = "text"
end

def to_s
Expand Down Expand Up @@ -196,7 +196,7 @@ def <=>(another)
def initialize(val)
self.value = val.clone
# val consists of :time && :zone values. If :zone is empty, floating local time (i.e. system local time) is assumed
self.type = "datetimeLocal"
self.type = "date-time"
# fill in unspecified month && year && date; only for purposes of comparison
val[:year] = sprintf("%04d", ::Date.today.year) unless val.has_key?(:year)
val[:month] = sprintf("%02d", ::Date.today.month) unless val.has_key?(:month)
Expand Down Expand Up @@ -282,7 +282,7 @@ def to_hash
class Utcoffset < Vobject::PropertyValue
def initialize(val)
self.value = val
self.type = "utcoffset"
self.type = "utc-offset"
end

def to_s
Expand All @@ -299,7 +299,7 @@ def to_hash
class Version < Vobject::PropertyValue
def initialize(val)
self.value = val
self.type = "version"
self.type = "text"
end

def to_s
Expand All @@ -314,7 +314,7 @@ def to_hash
class Gender < Vobject::PropertyValue
def initialize(val)
self.value = val
self.type = "gender"
self.type = "text"
end

def to_s
Expand All @@ -331,7 +331,7 @@ def to_hash
class Textlist < Vobject::PropertyValue
def initialize(val)
self.value = val
self.type = "textlist"
self.type = "text"
end

def to_s
Expand All @@ -346,7 +346,7 @@ def to_hash
class Org < Vobject::PropertyValue
def initialize(val)
self.value = val
self.type = "org"
self.type = "text"
end

def to_s
Expand All @@ -361,7 +361,7 @@ def to_hash
class Fivepartname < Vobject::PropertyValue
def initialize(val)
self.value = val
self.type = "fivepartname"
self.type = "text"
end

def to_s
Expand Down

0 comments on commit 0a70d52

Please sign in to comment.