Module: DocumentBuilder::Model::ClassMethods
- Defined in:
- lib/document_builder/model.rb
Instance Method Summary collapse
- #add_attribute(name, attribute) ⇒ Object
- #call(document) ⇒ Object
- #collection(name, selector: nil, type: nil) ⇒ Object
- #inherited(subclass) ⇒ Object
- #property(name, selector: nil, type: nil) ⇒ Object
- #root(selector) ⇒ Object
- #tag(name, selector: nil, type: nil) ⇒ Object
Instance Method Details
#add_attribute(name, attribute) ⇒ Object
4 5 6 7 |
# File 'lib/document_builder/model.rb', line 4 def add_attribute(name, attribute) @attributes ||= {} @attributes[name.to_sym] = attribute end |
#call(document) ⇒ Object
31 32 33 |
# File 'lib/document_builder/model.rb', line 31 def call(document) self.new(document) end |
#collection(name, selector: nil, type: nil) ⇒ Object
17 18 19 |
# File 'lib/document_builder/model.rb', line 17 def collection(name, selector: nil, type: nil) add_attribute name, Collection.new(name, selector: selector, type: type) end |
#inherited(subclass) ⇒ Object
25 26 27 28 29 |
# File 'lib/document_builder/model.rb', line 25 def inherited(subclass) subclass.instance_variable_set(:@attributes, @attributes) subclass.instance_variable_set(:@root, @root) super end |
#property(name, selector: nil, type: nil) ⇒ Object
9 10 11 |
# File 'lib/document_builder/model.rb', line 9 def property(name, selector: nil, type: nil) add_attribute name, Property.new(name, selector: selector, type: type) end |
#root(selector) ⇒ Object
21 22 23 |
# File 'lib/document_builder/model.rb', line 21 def root(selector) @root = selector end |
#tag(name, selector: nil, type: nil) ⇒ Object
13 14 15 |
# File 'lib/document_builder/model.rb', line 13 def tag(name, selector: nil, type: nil) add_attribute name, Tag.new(name, selector: selector, type: type) end |