Class: Mapricot::Base
- Inherits:
-
Object
- Object
- Mapricot::Base
- Defined in:
- lib/mapricot/base.rb
Overview
Inherit from base, e.g. class Animal < Mapricot::Base Use either a string of xml or a url to initialize
Class Method Summary collapse
- .association_list ⇒ Object
- .attribute_list ⇒ Object
- .has_attribute(name, type = :string) ⇒ Object
-
.has_many(name, type = :string, opts = {}) ⇒ Object
creates a new HasManyAssociation and appends it to the @association_list.
-
.has_one(name, type = :string, opts = {}) ⇒ Object
creates a new HasOneAssociation and appends it to the @association_list.
Instance Method Summary collapse
-
#initialize(str) ⇒ Base
constructor
class Foo < Mapricot::Base; end; Foo.new :url => “www.example.com” Foo.new :xml => %(<hi></hi>) the class instance variable @association_list is duplicated in every instance of Feed, as the instance variable @associations.
Constructor Details
#initialize(str) ⇒ Base
class Foo < Mapricot::Base; end; Foo.new :url => “www.example.com” Foo.new :xml => %(<hi></hi>) the class instance variable @association_list is duplicated in every instance of Feed, as the instance variable @associations. i.e. Feed.association_list is the template for feed.associations
47 48 49 50 51 52 |
# File 'lib/mapricot/base.rb', line 47 def initialize(str) @doc = AbstractDoc.new(correct_input_for_legacy_interface(str)) dup_associations_and_attributes map_associations map_attributes end |
Class Method Details
.association_list ⇒ Object
33 34 35 |
# File 'lib/mapricot/base.rb', line 33 def association_list @association_list ||= [] end |
.attribute_list ⇒ Object
37 38 39 |
# File 'lib/mapricot/base.rb', line 37 def attribute_list @attribute_list ||= [] end |
.has_attribute(name, type = :string) ⇒ Object
28 29 30 31 |
# File 'lib/mapricot/base.rb', line 28 def has_attribute(name, type = :string) attribute_list << Attribute.new(name, type) class_eval "attr_reader :#{name}", __FILE__, __LINE__ end |
.has_many(name, type = :string, opts = {}) ⇒ Object
creates a new HasManyAssociation and appends it to the @association_list
19 20 21 22 23 24 25 26 |
# File 'lib/mapricot/base.rb', line 19 def has_many(name, type = :string, opts = {}) association = HasManyAssociation.new(name, type, opts) if self.name.match(/::/) association.namespace = self.name.match(/(.*)::[^:]+$/)[1] end association_list << association class_eval "attr_reader :#{name}", __FILE__, __LINE__ end |
.has_one(name, type = :string, opts = {}) ⇒ Object
creates a new HasOneAssociation and appends it to the @association_list
9 10 11 12 13 14 15 16 |
# File 'lib/mapricot/base.rb', line 9 def has_one(name, type = :string, opts = {}) association = HasOneAssociation.new(name, type, opts) if self.name.match(/::/) association.namespace = self.name.match(/(.*)::[^:]+$/)[1] end association_list << association class_eval "attr_reader :#{name}", __FILE__, __LINE__ end |