Sha256: 8284008a0b82a464248a2ca0234e7b5d45e67527bc2f41e8b5f0bab7e4cf208b

Contents?: true

Size: 591 Bytes

Versions: 9

Compression:

Stored size: 591 Bytes

Contents

module ::Rubiks

  class Schema < NamedObject
    def cubes
      @cubes ||= []
    end

    def cube(cube_name, options={}, &block)
      cubes.push ::Rubiks::Cube.find_or_create(cube_name, options, &block)
    end

    def json_hash
      hash = default_json_attributes
      hash[:cubes] = cubes.map{ |c| c.json_hash } if cubes.present?
      hash.stringify_keys!
    end

    def to_xml(builder = nil)
      builder = builder || new_builder
      builder.instruct!

      builder.schema(:name => caption) do
        cubes.each{ |cube| cube.to_xml(builder) }
      end
    end
  end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rubiks-0.1.8 lib/rubiks/schema.rb
rubiks-0.1.7 lib/rubiks/schema.rb
rubiks-0.1.6 lib/rubiks/schema.rb
rubiks-0.1.5 lib/rubiks/schema.rb
rubiks-0.1.4 lib/rubiks/schema.rb
rubiks-0.1.3 lib/rubiks/schema.rb
rubiks-0.1.2 lib/rubiks/schema.rb
rubiks-0.1.1 lib/rubiks/schema.rb
rubiks-0.1.0 lib/rubiks/schema.rb