Module: Duxml::Meta

Included in:
MetaClass
Defined in:
lib/duxml/meta.rb,
lib/duxml/meta.rb

Constant Summary collapse

FILE_EXT =
'.duxml'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.meta_path(path) ⇒ String

Returns full path of metadata file based on content file’s name e.g. ‘design.xml’ => ‘.design.xml.duxml’.

Parameters:

  • path (String)

    path of XML-content file

Returns:

  • (String)

    full path of metadata file based on content file’s name e.g. ‘design.xml’ => ‘.design.xml.duxml’



32
33
34
35
# File 'lib/duxml/meta.rb', line 32

def self.meta_path(path)
  dir = File.dirname(path)
  "#{dir}/.#{File.basename(path)}#{FILE_EXT}"
end

Instance Method Details

#grammar=(g) ⇒ GrammarClass

Returns grammar object.

Parameters:

Returns:



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/duxml/meta.rb', line 39

def grammar=(g)
  @grammar = case g
               when GrammarClass then g
               when String
                 if File.exists?(g)
                   @grammar_path = g
                   Grammar.import(g)
                 else
                   maudule, meth = *g.split('.')
                   if Module.const_defined?(maudule.to_sym)
                     Module.const_get(maudule.to_sym).send(meth.to_sym)
                   else
                     raise ArgumentError, "#{g.to_s} is not a valid module/grammar symbol"
                   end
                 end
               else
                 raise ArgumentError, "#{g.to_s} is not a valid Grammar or path to one"
             end
  history.delete_observers if history.respond_to?(:delete_observers)
  history.add_observer(grammar, :qualify)
  grammar.add_observer history
  grammar
end

#xmlObject



63
64
65
66
67
68
69
70
71
# File 'lib/duxml/meta.rb', line 63

def xml
  if grammar_path
    g = Duxml::Element.new('grammar')
    g[:ref] = grammar_path
  else
    g = grammar.xml
  end
  Duxml::Element.new('meta') << g << history.xml
end