Sha256: f17b58d09c702e329742f957c938771d02561499d3f35ad4ba35170da5db53df

Contents?: true

Size: 735 Bytes

Versions: 2

Compression:

Stored size: 735 Bytes

Contents

require "nokogiri"

module Tim
  class Template < Tim::Base
    include ActiveModel::Validations
    validates_with TemplateValidator

    has_many :base_images, :inverse_of => :template

    attr_accessible :xml
    attr_protected :id

    OS = Struct.new(:name, :version, :arch)

    # Used in views to display the xml elements of this template
    def xml_elements
      parsed_xml.xpath("//template/*").to_xml
    end

    def os
      OS.new(
        parsed_xml.xpath("//template/os/name").text,
        parsed_xml.xpath("//template/os/version").text,
        parsed_xml.xpath("//template/os/arch").text
      )
    end

    private

    def parsed_xml
      @parsed_xml ||= ::Nokogiri::XML::Document.parse(xml)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tim-0.3.0 app/models/tim/template.rb
tim-0.2.0 app/models/tim/template.rb