Module: Goldendocx::Element

Extended by:
ActiveSupport::Concern
Includes:
HasAttributes, HasChildren
Included in:
Charts::CategoryAxis, Charts::Properties::AutoTitleDeletedProperty, Charts::Properties::AxisProperty, Charts::Properties::BarChartProperty, Charts::Properties::ChartProperty, Charts::Properties::ColumnChartProperty, Charts::Properties::CrossAxisProperty, Charts::Properties::DataLabelsProperty, Charts::Properties::DirectionProperty, Charts::Properties::DoughnutChartProperty, Charts::Properties::GroupingProperty, Charts::Properties::HoleProperty, Charts::Properties::IndexProperty, Charts::Properties::LabelHiddenProperty, Charts::Properties::LayoutProperty, Charts::Properties::LineChartProperty, Charts::Properties::MarkerProperty, Charts::Properties::NumberListProperty, Charts::Properties::OrderProperty, Charts::Properties::PlotAreaProperty, Charts::Properties::PointCountProperty, Charts::Properties::PointProperty, Charts::Properties::Reference, Charts::Properties::RoundedCornerProperty, Charts::Properties::SeriesCategoryProperty, Charts::Properties::SeriesTextProperty, Charts::Properties::SeriesValueProperty, Charts::Properties::SmoothProperty, Charts::Properties::StringListProperty, Charts::Properties::SymbolProperty, Charts::Properties::TextValueProperty, Charts::Series, Charts::ValueAxis, Components::Image, Components::Paragraph, Components::Properties::AlignProperty, Components::Properties::BoldProperty, Components::Properties::ColorProperty, Components::Properties::Drawing, Components::Properties::ExtentsProperty, Components::Properties::FontProperty, Components::Properties::GraphicDataProperty, Components::Properties::GraphicFrameLocksProperty, Components::Properties::GraphicFrameProperty, Components::Properties::GraphicProperty, Components::Properties::Inline, Components::Properties::LanguageProperty, Components::Properties::NonVisualProperty, Components::Properties::PaddingProperty, Components::Properties::Property, Components::Properties::Run, Components::Properties::RunProperty, Components::Properties::StyleProperty, Components::Properties::Textual, Components::Table, Components::Text, ContentTypes::Default, ContentTypes::Override, Document, Documents::Body, Documents::LatentStyles, Documents::Properties::DefaultStyleProperty, Documents::Properties::PageMarginProperty, Documents::Properties::PageSizeProperty, Documents::Properties::ParagraphDefaultStyleProperty, Documents::Properties::RunDefaultStyleProperty, Documents::Properties::SectionProperty, Documents::Properties::StyleNameProperty, Documents::Style, Images::Picture, Images::Properties::BlipProperty, Images::Properties::DrawingProperty, Images::Properties::ExtentsProperty, Images::Properties::FillRectangleProperty, Images::Properties::ImageDataProperty, Images::Properties::NonVisualDrawingProperty, Images::Properties::NonVisualPictureProperty, Images::Properties::PictureFillProperty, Images::Properties::PictureShapeProperty, Images::Properties::ShapeProperty, Images::Properties::StretchProperty, Images::Properties::TransformProperty, Images::Shape, Models::Relationship, Parts::Properties::CreatedAtProperty, Parts::Properties::CreatorProperty, Parts::Properties::RevisionProperty, Parts::Properties::UpdatedAtProperty, Parts::Properties::UpdaterProperty, Tables::Cell, Tables::HeaderRow, Tables::Properties::CellProperty, Tables::Properties::CellWidthProperty, Tables::Properties::GridColumnProperty, Tables::Properties::GridProperty, Tables::Properties::GridSpanProperty, Tables::Properties::HeaderRowProperty, Tables::Properties::Property, Tables::Properties::RowHeightProperty, Tables::Properties::RowProperty, Tables::Properties::ShadingProperty, Tables::Properties::StyleProperty, Tables::Properties::VerticalAlignProperty, Tables::Properties::WidthProperty, Tables::Row
Defined in:
lib/goldendocx/element.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Methods included from HasChildren

#children, #read_child, #read_children

Methods included from HasAttributes

#assign_attributes, #attributes, #read_attributes

Instance Method Details

#build_element(xml) {|xml| ... } ⇒ Object

Yields:

  • (xml)


75
76
77
78
79
80
81
82
83
# File 'lib/goldendocx/element.rb', line 75

def build_element(xml)
  attributes.each { |name, value| xml[name] = value }
  unparsed_attributes.each { |name, value| xml[name] = value }

  children.each { |child| xml << child }
  unparsed_children.each { |child| xml << child }

  yield(xml) if block_given?
end

#initialize(attributes = nil) ⇒ Object



50
51
52
53
# File 'lib/goldendocx/element.rb', line 50

def initialize(attributes = nil)
  attributes ||= {}
  assign_attributes(**attributes)
end

#namespaceObject



59
60
61
# File 'lib/goldendocx/element.rb', line 59

def namespace
  self.class.concerning_ancestors.find { |ancestor| ancestor.namespace.present? }&.namespace
end

#tagObject



55
56
57
# File 'lib/goldendocx/element.rb', line 55

def tag
  self.class.concerning_ancestors.find { |ancestor| ancestor.tag.present? }&.tag
end

#tag_nameObject



63
64
65
# File 'lib/goldendocx/element.rb', line 63

def tag_name
  @tag_name ||= [namespace, tag].compact.join(':')
end

#to_element(**context) ⇒ Object



67
68
69
# File 'lib/goldendocx/element.rb', line 67

def to_element(**context, &)
  Goldendocx.xml_serializer.build_element(tag_name, **context) { |xml| build_element(xml, &) }
end

#to_xmlObject



71
72
73
# File 'lib/goldendocx/element.rb', line 71

def to_xml(&)
  Goldendocx.xml_serializer.build_xml(tag_name) { |xml| build_element(xml, &) }
end