Class: Fanfeedrb::Fanfeedr::Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/fanfeedrb/fanfeedr.rb

Overview

end

Direct Known Subclasses

Conference, Event, Geo, League, Team

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Abstract.

Yields:

  • (_self)

Yield Parameters:



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/fanfeedrb/fanfeedr.rb', line 74

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



101
102
103
104
105
106
# File 'lib/fanfeedrb/fanfeedr.rb', line 101

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



92
93
94
95
96
97
98
99
# File 'lib/fanfeedrb/fanfeedr.rb', line 92

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



86
87
88
89
90
# File 'lib/fanfeedrb/fanfeedr.rb', line 86

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

Instance Method Details

#idObject



108
109
110
# File 'lib/fanfeedrb/fanfeedr.rb', line 108

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

#to_xmlObject



112
113
114
# File 'lib/fanfeedrb/fanfeedr.rb', line 112

def to_xml
  Fanfeedrb.hash_to_xml(self.class.name.split('::').last.downcase, @attributes)
end