Module: Muffins::ClassMethods

Defined in:
lib/muffins/class_methods.rb

Instance Method Summary collapse

Instance Method Details

#map(name, type, options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/muffins/class_methods.rb', line 5

def map(name, type, options = {})
  options[:name] = name
  options[:type] = type

  mapping = Mapping.new(options)

  add_mapping(mapping)
  add_attribute(name, type)

  self
end

#parse(doc, options = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/muffins/class_methods.rb', line 23

def parse(doc, options = {})
  document = Muffins::Document.new(:body => doc.to_s)

  if options[:single]
    new_from_node(document.first(path))
  else
    document.map(path) { |node| new_from_node(node) }
  end
end

#within(path, &block) ⇒ Object



18
19
20
# File 'lib/muffins/class_methods.rb', line 18

def within(path, &block)
  Muffins::MappingParent.new(:path => path, :klass => self).tap { |parent| yield parent }
end