Class: Pickler::Tracker::Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/pickler/tracker.rb

Direct Known Subclasses

Iteration, Note, Project, Story

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) {|_self| ... } ⇒ Abstract

Returns a new instance of Abstract.

Yields:

  • (_self)

Yield Parameters:



70
71
72
73
74
75
76
# File 'lib/pickler/tracker.rb', line 70

def initialize(attributes = {})
  @attributes = {}
  (attributes || {}).each do |k,v|
    @attributes[k.to_s] = v
  end
  yield self if block_given?
end

Class Method Details

.accessor(*methods) ⇒ Object



93
94
95
96
97
98
# File 'lib/pickler/tracker.rb', line 93

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



84
85
86
87
88
89
90
91
# File 'lib/pickler/tracker.rb', line 84

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



78
79
80
81
82
# File 'lib/pickler/tracker.rb', line 78

def self.reader(*methods)
  methods.each do |method|
    define_method(method) { @attributes[method.to_s] }
  end
end

Instance Method Details

#idObject



100
101
102
# File 'lib/pickler/tracker.rb', line 100

def id
  id = @attributes['id'] and Integer(id)
end

#to_xml(options = nil) ⇒ Object



104
105
106
# File 'lib/pickler/tracker.rb', line 104

def to_xml(options = nil)
  @attributes.to_xml({:dasherize => false, :root => self.class.name.split('::').last.downcase}.merge(options||{}))
end