Class: Vobject::Property
- Inherits:
-
Object
- Object
- Vobject::Property
- Defined in:
- lib/vobject/property.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#group ⇒ Object
Returns the value of attribute group.
-
#multiple ⇒ Object
Returns the value of attribute multiple.
-
#norm ⇒ Object
Returns the value of attribute norm.
-
#params ⇒ Object
Returns the value of attribute params.
-
#prop_name ⇒ Object
Returns the value of attribute prop_name.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #<=>(another) ⇒ Object
-
#initialize(key, options) ⇒ Property
constructor
A new instance of Property.
- #to_hash ⇒ Object
- #to_norm ⇒ Object
- #to_norm_line ⇒ Object
- #to_s ⇒ Object
- #to_s_line ⇒ Object
Constructor Details
#initialize(key, options) ⇒ Property
Returns a new instance of Property.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/vobject/property.rb', line 17 def initialize(key, ) if .class == Array self.multiple = [] .each do |v| multiple << property_base_class.new(key, v) self.prop_name = key end else self.prop_name = key if .nil? || .empty? self.group = nil self.params = [] self.value = nil else self.group = [:group] self.prop_name = key unless [:params].nil? || [:params].empty? self.params = [] [:params].each do |k, v| params << parameter_base_class.new(k, v) end end # self.value = parse_value(options[:value]) self.value = [:value] end end self.norm = nil raise_invalid_initialization if key != name end |
Instance Attribute Details
#group ⇒ Object
Returns the value of attribute group.
5 6 7 |
# File 'lib/vobject/property.rb', line 5 def group @group end |
#multiple ⇒ Object
Returns the value of attribute multiple.
5 6 7 |
# File 'lib/vobject/property.rb', line 5 def multiple @multiple end |
#norm ⇒ Object
Returns the value of attribute norm.
5 6 7 |
# File 'lib/vobject/property.rb', line 5 def norm @norm end |
#params ⇒ Object
Returns the value of attribute params.
5 6 7 |
# File 'lib/vobject/property.rb', line 5 def params @params end |
#prop_name ⇒ Object
Returns the value of attribute prop_name.
5 6 7 |
# File 'lib/vobject/property.rb', line 5 def prop_name @prop_name end |
#value ⇒ Object
Returns the value of attribute value.
5 6 7 |
# File 'lib/vobject/property.rb', line 5 def value @value end |
Instance Method Details
#<=>(another) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/vobject/property.rb', line 7 def <=>(another) if self.prop_name =~ /^VERSION$/i -1 elsif another.prop_name =~ /^VERSION$/i 1 else self.to_norm <=> another.to_norm end end |
#to_hash ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/vobject/property.rb', line 107 def to_hash ret = {} if multiple ret[prop_name] = [] multiple.each do |c| ret[prop_name] = ret[prop_name] << c.to_hash[prop_name] end else ret = {prop_name => { value: value.to_hash } } ret[prop_name][:group] = group unless group.nil? if params ret[prop_name][:params] = {} params.each do |p| ret[prop_name][:params] = ret[prop_name][:params].merge p.to_hash end end end ret end |
#to_norm ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/vobject/property.rb', line 75 def to_norm if @norm.nil? if multiple.nil? || multiple.empty? ret = to_norm_line else arr = [] multiple.sort.each do |x| arr << x.to_norm_line end ret = arr.join("") end @norm = ret end @norm end |
#to_norm_line ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/vobject/property.rb', line 91 def to_norm_line line = group ? "#{group}." : "" line << name.to_s.tr("_", "-").upcase (params || {}).sort.each do |p| line << ";#{p.to_norm}" end line << ":#{value.to_norm}" line = Vobject::fold_line(line) << "\n" line end |
#to_s ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/vobject/property.rb', line 47 def to_s if multiple.nil? || multiple.empty? ret = to_s_line else arr = [] multiple.each do |x| arr << x.to_s_line end ret = arr.join("") end ret end |
#to_s_line ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/vobject/property.rb', line 60 def to_s_line line = group ? "#{group}." : "" line << name.to_s.tr("_", "-") (params || {}).each do |p| line << ";#{p}" end line << ":#{value}" line = Vobject::fold_line(line) << "\n" line end |