Class: Pickler::Tracker::Abstract
- Inherits:
-
Object
- Object
- Pickler::Tracker::Abstract
show all
- Defined in:
- lib/pickler/tracker.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(attributes = {}) {|_self| ... } ⇒ Abstract
Returns a new instance of Abstract.
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/pickler/tracker.rb', line 70
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
|
Class Method Details
.accessor(*methods) ⇒ Object
97
98
99
100
101
102
|
# File 'lib/pickler/tracker.rb', line 97
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
88
89
90
91
92
93
94
95
|
# File 'lib/pickler/tracker.rb', line 88
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
82
83
84
85
86
|
# File 'lib/pickler/tracker.rb', line 82
def self.reader(*methods)
methods.each do |method|
define_method(method) { @attributes[method.to_s] }
end
end
|
Instance Method Details
#id ⇒ Object
104
105
106
|
# File 'lib/pickler/tracker.rb', line 104
def id
id = @attributes['id'] and Integer(id)
end
|
#to_xml(options = nil) ⇒ Object
108
109
110
|
# File 'lib/pickler/tracker.rb', line 108
def to_xml(options = nil)
@attributes.to_xml({:dasherize => false, :root => self.class.name.split('::').last.downcase}.merge(options||{}))
end
|