5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/virginity/vcard/field_values/optional_structured_text.rb', line 5
def self.define(components)
m = super
m.module_eval <<-RUBY, __FILE__, __LINE__+1
def reencode!(options = {})
v = values
v.pop while v.last.empty?
@value = EncodingDecoding::encode_structured_text(v)
end
RUBY
components.each_with_index do |component, idx|
m.module_eval <<-RUBY, __FILE__, __LINE__+1
def #{component}=(new_value)
structure = values
structure[#{idx}] = new_value.to_s
structure.pop while structure.size > 0 && (structure.last.nil? || structure.last.empty?)
@value = EncodingDecoding::encode_structured_text(structure)
end
RUBY
end
m
end
|