lib/vcard/dirinfo.rb in vcard-0.2.16 vs lib/vcard/dirinfo.rb in vcard-0.3.0

- old
+ new

@@ -90,14 +90,15 @@ # and see Field#create(). def DirectoryInfo.create(fields = [], profile = nil) if profile p = profile.to_str - f = [ Field.create("BEGIN", p) ] - f.concat fields - f.push Field.create("END", p) - fields = f + fields = [ + Field.create("BEGIN", p), + *fields, + Field.create("END", p) + ] end new(fields, profile) end @@ -190,13 +191,12 @@ # Returns an Enumerator for each Field for which +cond+.call(field) is true. def enum_by_cond(cond) Enumerator.new(self, cond ) end - # Force card to be reencoded from the fields. + # Obsoleted; force card to be reencoded from the fields. def dirty #:nodoc: - #string = nil end # Append +field+ to the fields. Note that it won't be literally appended # to the fields, it will be inserted before the closing END field. def push(field) @@ -239,17 +239,16 @@ end self end + LF= "\n" + # The string encoding of the DirectoryInfo. See Field#encode for information - # about the width parameter. - def encode(width=nil) - unless @string - @string = @fields.collect { |f| f.encode(width) } . join "" - end - @string + # about the parameters. + def encode(width = 75, nl: LF) + @fields.collect { |f| f.encode(width, nl: nl) }.join end alias to_s encode # Check that the DirectoryInfo object is correctly delimited by a BEGIN @@ -258,13 +257,13 @@ def check_begin_end(profile=nil) #:nodoc: unless @fields.first raise "No fields to check" end unless @fields.first.name? "BEGIN" - raise "Needs BEGIN, found: #{@fields.first.encode nil}" + raise "Needs BEGIN, found: #{@fields.first.encode}" end unless @fields.last.name? "END" - raise "Needs END, found: #{@fields.last.encode nil}" + raise "Needs END, found: #{@fields.last.encode}" end unless @fields.last.value? @fields.first.value raise "BEGIN/END mismatch: (#{@fields.first.value} != #{@fields.last.value}" end if profile