Class: XamplGenerator::Element

Inherits:
Object
  • Object
show all
Includes:
Xampl::XamplObject, Xampl::XamplWithDataContent, AttributeAsChild, ChildElementAsChild
Defined in:
lib/xamplr/xampl-generator.rb,
lib/xamplr/xampl-hand-generated.rb

Constant Summary collapse

@@tag =
"element"
@@ns =
"http://xampl.com/generator"
@@ns_tag =
"{http://xampl.com/generator}element"
@@module_name =
"XamplGenerator"
@@attributes =
[
        [ :@has_content, "hasContent" ],
                [ :@class_name, "className" ],
                [ :@attribute_name, "attributeName" ],
                [ :@nstag, "nstag" ],
                [ :@empty, "empty" ],
                [ :@indexed_by_attr, "indexedByAttr" ],
                [ :@persisted, "persisted" ],
                [ :@name, "name" ],
                [ :@kind, "kind" ],
                [ :@namespace, "namespace" ],
                [ :@package, "package" ],
]

Instance Attribute Summary

Attributes included from Xampl::XamplObject

#is_changed, #parents

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AttributeAsChild

#add_attribute, #attribute_child, #attribute_child=, #ensure_attribute, #init_attribute_as_child, #new_attribute, #remove_attribute

Methods included from ChildElementAsChild

#add_child_element, #child_element_child, #child_element_child=, #ensure_child_element, #init_child_element_as_child, #new_child_element, #remove_child_element

Methods included from Xampl::XamplWithDataContent

#<<, #_content, #_content=, #add_content, #after_visit_by_element_kind, #before_visit_by_element_kind, #children, #has_mixed_content, #init_data_content, #test_to_xml, #test_to_xml_internal, #visit_by_element_kind

Methods included from Xampl::XamplObject

#===, #accessed, #add_parent, #changed, #changes_accepted, #compare_xampl, #copy_xampl, from_ruby, from_string, from_xml_file, from_xml_string, #ignore_when_no_index, #init_attributes, #init_hook, #init_xampl_object, #invalid, #invalidate, lookup_preferred_ns_prefix, #mark_changed_deep, #note_add_child, #note_add_to_parent, #note_adding_text_content, #note_attributes_initialised, #note_closed, #note_created, #note_initialise_attributes_with, #note_invalidate, #note_replacing, ns_preferred_prefix, #persist, #persist_required, #pp_xml, realise_from_xml_string, recover_from_string, #to_ruby, #to_xml

Constructor Details

#initialize(index = nil) {|_self| ... } ⇒ Element

Returns a new instance of Element.

Yields:

  • (_self)

Yield Parameters:



744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
# File 'lib/xamplr/xampl-hand-generated.rb', line 744

def initialize(index=nil)
  @name = index if index
  super()

  @has_content = nil if not defined? @has_content
  @class_name = nil if not defined? @class_name
  @attribute_name = nil if not defined? @attribute_name
  @nstag = nil if not defined? @nstag
  @empty = nil if not defined? @empty
  @indexed_by_attr = nil if not defined? @indexed_by_attr
  @persisted = nil if not defined? @persisted
  @name = nil if not defined? @name
  @kind = nil if not defined? @kind
  @namespace = nil if not defined? @namespace
  @package = nil if not defined? @package

  init_xampl_object
  init_data_content
  init_child_element_as_child
  init_attribute_as_child

  yield(self) if block_given?
  changed
end

Class Method Details

.module_nameObject



799
800
801
# File 'lib/xamplr/xampl-hand-generated.rb', line 799

def Element.module_name
  @@module_name
end

.nsObject



791
792
793
# File 'lib/xamplr/xampl-hand-generated.rb', line 791

def Element.ns
  @@ns
end

.ns_tagObject



795
796
797
# File 'lib/xamplr/xampl-hand-generated.rb', line 795

def Element.ns_tag
  @@ns_tag
end

.persisted?Boolean

Returns:

  • (Boolean)


595
596
597
# File 'lib/xamplr/xampl-hand-generated.rb', line 595

def Element.persisted?
  false
end

.tagObject



787
788
789
# File 'lib/xamplr/xampl-hand-generated.rb', line 787

def Element.tag
  @@tag
end

Instance Method Details

#after_visit(visitor) ⇒ Object



847
848
849
# File 'lib/xamplr/xampl-hand-generated.rb', line 847

def after_visit(visitor)
  visitor.after_visit_element(self)
end

#analyse(options) ⇒ Object



422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
# File 'lib/xamplr/xampl-generator.rb', line 422

def analyse(options)
  is_empty, is_simple, is_data, is_mixed = false

  class_name, attribute_name = Generator.choose_names(@name)
  @class_name = class_name unless @class_name
  @attribute_name = attribute_name unless @attribute_name

  no_children = (0 == @child_element_child.size)

  unless @kind then
    if no_children then
      is_simple = @has_content
      is_empty = !is_simple
    else
      is_mixed = @has_content
      is_data = !@has_content
    end

    # this isn't a very strong piece of information, can't do much about it.
    #attribute_like = ((0 == @attribute_child.size) and is_simple)

    if    is_empty  then
      @kind = "empty"
    elsif is_simple then
      @kind = "simple"
    elsif is_data   then
      @kind = "data"
    elsif is_mixed  then
      @kind = "mixed"
    else
      throw "no kind determined" # this should be impossible
    end
  end

  unless self.indexed_by_attr then
    attribute_child.each do |attribute|
      aname_orig = attribute.name
      class_name, aname = Generator.choose_names(aname_orig)
      attribute.name = aname
      attribute.tag_name = aname_orig

      options.index_attribute_child.each do |iattr|
        if aname == iattr.name then
          self.indexed_by_attr = aname
          self.persisted = iattr.persisted
          break
        end
      end
    end
  end
end

#append_to(other) ⇒ Object



783
784
785
# File 'lib/xamplr/xampl-hand-generated.rb', line 783

def append_to(other)
  other.add_element(self)
end

#attribute_nameObject



645
646
647
648
# File 'lib/xamplr/xampl-hand-generated.rb', line 645

def attribute_name
  accessed
  @attribute_name
end

#attribute_name=(v) ⇒ Object



650
651
652
653
654
# File 'lib/xamplr/xampl-hand-generated.rb', line 650

def attribute_name=(v)
  accessed
  changed
  @attribute_name = v
end

#attributesObject



819
820
821
# File 'lib/xamplr/xampl-hand-generated.rb', line 819

def attributes
  @@attributes
end

#before_visit(visitor) ⇒ Object



839
840
841
# File 'lib/xamplr/xampl-hand-generated.rb', line 839

def before_visit(visitor)
  visitor.before_visit_element(self)
end

#class_nameObject



634
635
636
637
# File 'lib/xamplr/xampl-hand-generated.rb', line 634

def class_name
  accessed
  @class_name
end

#class_name=(v) ⇒ Object



639
640
641
642
643
# File 'lib/xamplr/xampl-hand-generated.rb', line 639

def class_name=(v)
  accessed
  changed
  @class_name = v
end

#clear_non_persistent_index_attributesObject



769
770
771
772
773
774
775
776
777
778
779
780
781
# File 'lib/xamplr/xampl-hand-generated.rb', line 769

def clear_non_persistent_index_attributes
  @has_content = nil
  @class_name = nil
  @attribute_name = nil
  @nstag = nil
  @empty = nil
  @indexed_by_attr = nil
  @persisted = nil
  @name = nil
  @kind = nil
  @namespace = nil
  @package = nil
end

#emptyObject



667
668
669
670
# File 'lib/xamplr/xampl-hand-generated.rb', line 667

def empty
  accessed
  @empty
end

#empty=(v) ⇒ Object



672
673
674
675
676
# File 'lib/xamplr/xampl-hand-generated.rb', line 672

def empty=(v)
  accessed
  changed
  @empty = v
end

#found_text_contentObject



418
419
420
# File 'lib/xamplr/xampl-generator.rb', line 418

def found_text_content
  self.has_content = true
end

#get_the_indexObject



827
828
829
# File 'lib/xamplr/xampl-hand-generated.rb', line 827

def get_the_index
  @name
end

#has_contentObject



623
624
625
626
# File 'lib/xamplr/xampl-hand-generated.rb', line 623

def has_content
  accessed
  @has_content
end

#has_content=(v) ⇒ Object



628
629
630
631
632
# File 'lib/xamplr/xampl-hand-generated.rb', line 628

def has_content=(v)
  accessed
  changed
  @has_content = v
end

#indexed_byObject



823
824
825
# File 'lib/xamplr/xampl-hand-generated.rb', line 823

def indexed_by
  :name
end

#indexed_by_attrObject



678
679
680
681
# File 'lib/xamplr/xampl-hand-generated.rb', line 678

def indexed_by_attr
  accessed
  @indexed_by_attr
end

#indexed_by_attr=(v) ⇒ Object



683
684
685
686
687
# File 'lib/xamplr/xampl-hand-generated.rb', line 683

def indexed_by_attr=(v)
  accessed
  changed
  @indexed_by_attr = v
end

#kindObject



711
712
713
714
# File 'lib/xamplr/xampl-hand-generated.rb', line 711

def kind
  accessed
  @kind
end

#kind=(v) ⇒ Object



716
717
718
719
720
# File 'lib/xamplr/xampl-hand-generated.rb', line 716

def kind=(v)
  accessed
  changed
  @kind = v
end

#module_nameObject



815
816
817
# File 'lib/xamplr/xampl-hand-generated.rb', line 815

def module_name
  @@module_name
end

#nameObject



700
701
702
703
# File 'lib/xamplr/xampl-hand-generated.rb', line 700

def name
  accessed
  @name
end

#name=(v) ⇒ Object



705
706
707
708
709
# File 'lib/xamplr/xampl-hand-generated.rb', line 705

def name=(v)
  accessed
  changed
  @name = v
end

#namespaceObject



722
723
724
725
# File 'lib/xamplr/xampl-hand-generated.rb', line 722

def namespace
  accessed
  @namespace
end

#namespace=(v) ⇒ Object



727
728
729
730
731
# File 'lib/xamplr/xampl-hand-generated.rb', line 727

def namespace=(v)
  accessed
  changed
  @namespace = v
end

#nsObject



807
808
809
# File 'lib/xamplr/xampl-hand-generated.rb', line 807

def ns
  @@ns
end

#ns_tagObject



811
812
813
# File 'lib/xamplr/xampl-hand-generated.rb', line 811

def ns_tag
  @@ns_tag
end

#nstagObject



656
657
658
659
# File 'lib/xamplr/xampl-hand-generated.rb', line 656

def nstag
  accessed
  @nstag
end

#nstag=(v) ⇒ Object



661
662
663
664
665
# File 'lib/xamplr/xampl-hand-generated.rb', line 661

def nstag=(v)
  accessed
  changed
  @nstag = v
end

#packageObject



733
734
735
736
# File 'lib/xamplr/xampl-hand-generated.rb', line 733

def package
  accessed
  @package
end

#package=(v) ⇒ Object



738
739
740
741
742
# File 'lib/xamplr/xampl-hand-generated.rb', line 738

def package=(v)
  accessed
  changed
  @package = v
end

#persistedObject



689
690
691
692
# File 'lib/xamplr/xampl-hand-generated.rb', line 689

def persisted
  accessed
  @persisted
end

#persisted=(v) ⇒ Object



694
695
696
697
698
# File 'lib/xamplr/xampl-hand-generated.rb', line 694

def persisted=(v)
  accessed
  changed
  @persisted = v
end

#persisted?Boolean

Returns:

  • (Boolean)


599
600
601
# File 'lib/xamplr/xampl-hand-generated.rb', line 599

def persisted?
  false
end

#set_the_index(index) ⇒ Object



831
832
833
# File 'lib/xamplr/xampl-hand-generated.rb', line 831

def set_the_index(index)
  @name = index
end

#substitute_in_visit(visitor) ⇒ Object



835
836
837
# File 'lib/xamplr/xampl-hand-generated.rb', line 835

def substitute_in_visit(visitor)
  return visitor.substitute_in_visit_element(self) || self
end

#tagObject



803
804
805
# File 'lib/xamplr/xampl-hand-generated.rb', line 803

def tag
  @@tag
end

#visit(visitor) ⇒ Object



843
844
845
# File 'lib/xamplr/xampl-hand-generated.rb', line 843

def visit(visitor)
  visitor.visit_element(self)
end