Sha256: 15573e2cf21ab26cfdc41035db389e33cdfcf7acc20c612c23bfd5de889ff7b7

Contents?: true

Size: 1.21 KB

Versions: 7

Compression:

Stored size: 1.21 KB

Contents

require 'osheet/partial_set'
require 'osheet/template'

module Osheet
  class TemplateSet < PartialSet

    # this class is a PartialSet that keys off of the template element
    #  and name.  Only Osheet::Template objs can be pushed, and you reference
    #  a particular template using a key of

    def initialize
      super
    end

    # return the template set for the named element
    def get(element, name)
      lookup(key(element.to_s, name.to_s))
    end

    private

    def lookup(key)
      self[key.first][key.last] if self[key.first]
    end

    # push the template onto the key
    def push(key, template)
      self[key.first][key.last] = template
    end

    # verify the template, init the key set, and return the key string
    #  otherwise ArgumentError it up
    def verify(template)
      unless template.kind_of?(Template)
        raise ArgumentError, 'you can only push Osheet::Template objs to the template set'
      end
      key = template_key(template)
      self[key.first] ||= {}
      self[key.first][key.last] ||= nil
      key
    end

    def template_key(template)
      key(template.element, template.name)
    end

    def key(element, name)
      [element.to_s, name.to_s]
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
osheet-0.10.0 lib/osheet/template_set.rb
osheet-0.9.2 lib/osheet/template_set.rb
osheet-0.9.1 lib/osheet/template_set.rb
osheet-0.9.0 lib/osheet/template_set.rb
osheet-0.8.0 lib/osheet/template_set.rb
osheet-0.7.0 lib/osheet/template_set.rb
osheet-0.6.0 lib/osheet/template_set.rb