class DTK::DSL::FileGenerator::ContentInput::Tag
Constants
- BASE_LEVEL_TAGS
- DELIMITER
In this module a 'tag_type' subsumes a tag and consitutes an element in
BASE_LEVEL_TAGS
or one its prefixes
Attributes
name[R]
Public Class Methods
matches_tag_type?(tag_type, tag)
click to toggle source
# File lib/dsl/file_generator/content_input/tag.rb, line 60 def self.matches_tag_type?(tag_type, tag) tag_type_split = split(tag_type) tag_split = split(tag.name) if tag_split.size >= tag_type_split.size tag_type_split.each_with_index do |tag_type_part, i| return nil unless tag_type_part == tag_split[i] end true end end
new(tag_name)
click to toggle source
# File lib/dsl/file_generator/content_input/tag.rb, line 25 def initialize(tag_name) @name = tag_name end
Private Class Methods
compute_valid_tag_types()
click to toggle source
Iterates over BASE_LEVEL_TAGS
and puts in prefixes
# File lib/dsl/file_generator/content_input/tag.rb, line 102 def self.compute_valid_tag_types ret = [] BASE_LEVEL_TAGS.each do |tag| tag_split = split(tag) until tag_split.empty? ret << join(tag_split) tag_split.pop end end ret.uniq end
create(tag_input)
click to toggle source
# File lib/dsl/file_generator/content_input/tag.rb, line 30 def self.create(tag_input) tag = if tag_input.kind_of?(::String) or tag_input.kind_of?(::Symbol) Simple.new(tag_input.to_sym) elsif tag_input.kind_of?(::Hash) and tag_input.size == 1 tag_name = tag_input.keys.first if tag_name.kind_of?(::String) or tag_name.kind_of?(::Symbol) tag_value = tag_input.values.first Assignment.new(tag_name.to_sym, tag_value) end end raise Error, "Invalid form for a tag: #{tag_input.inspect}" unless tag raise Error, "Invalid tag name '#{tag.name}'" unless tag.valid_tag_name? tag end
join(t_split)
click to toggle source
# File lib/dsl/file_generator/content_input/tag.rb, line 118 def self.join(t_split) t_split.map(&:to_s).join(DELIMITER).to_sym end
split(t)
click to toggle source
# File lib/dsl/file_generator/content_input/tag.rb, line 114 def self.split(t) t.to_s.split(DELIMITER).map(&:to_sym) end
valid_tag_types()
click to toggle source
# File lib/dsl/file_generator/content_input/tag.rb, line 97 def self.valid_tag_types @valid_tag_tag_types ||= compute_valid_tag_types end
Public Instance Methods
valid_tag_name?()
click to toggle source
# File lib/dsl/file_generator/content_input/tag.rb, line 84 def valid_tag_name? self.class.valid_tag_types.include?(name) end