Class: Pickler::Tracker::Abstract
- Inherits:
-
Object
- Object
- Pickler::Tracker::Abstract
show all
- Defined in:
- lib/pickler/tracker.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(attributes = {}) {|_self| ... } ⇒ Abstract
Returns a new instance of Abstract.
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/pickler/tracker.rb', line 72
def initialize(attributes = {})
@attributes = {}
(attributes || {}).each do |k,v|
if respond_to?("#{k}=")
send("#{k}=", v)
else
@attributes[k.to_s] = v
end
end
yield self if block_given?
end
|
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
70
71
72
|
# File 'lib/pickler/tracker.rb', line 70
def attributes
@attributes
end
|
Class Method Details
.accessor(*methods) ⇒ Object
99
100
101
102
103
104
|
# File 'lib/pickler/tracker.rb', line 99
def self.accessor(*methods)
reader(*methods)
methods.each do |method|
define_method("#{method}=") { |v| attributes[method.to_s] = v }
end
end
|
.date_reader(*methods) ⇒ Object
90
91
92
93
94
95
96
97
|
# File 'lib/pickler/tracker.rb', line 90
def self.date_reader(*methods)
methods.each do |method|
define_method(method) do
value = attributes[method.to_s]
value.kind_of?(String) ? Date.parse(value) : value
end
end
end
|
.reader(*methods) ⇒ Object
84
85
86
87
88
|
# File 'lib/pickler/tracker.rb', line 84
def self.reader(*methods)
methods.each do |method|
define_method(method) { attributes[method.to_s] }
end
end
|
Instance Method Details
#id ⇒ Object
106
107
108
|
# File 'lib/pickler/tracker.rb', line 106
def id
id = attributes['id'] and Integer(id)
end
|
#to_xml ⇒ Object
110
111
112
|
# File 'lib/pickler/tracker.rb', line 110
def to_xml
Pickler.hash_to_xml(self.class.name.split('::').last.downcase, attributes)
end
|