Class: Mondrian::OLAP::SchemaElement
- Inherits:
-
Object
- Object
- Mondrian::OLAP::SchemaElement
show all
- Defined in:
- lib/mondrian/olap/schema_element.rb
Direct Known Subclasses
Schema, Mondrian::OLAP::Schema::AggExclude, Mondrian::OLAP::Schema::AggFactCount, Mondrian::OLAP::Schema::AggForeignKey, Mondrian::OLAP::Schema::AggIgnoreColumn, Mondrian::OLAP::Schema::AggLevel, Mondrian::OLAP::Schema::AggMeasure, Mondrian::OLAP::Schema::AggName, Mondrian::OLAP::Schema::AggPattern, Mondrian::OLAP::Schema::Annotation, Mondrian::OLAP::Schema::Annotations, Mondrian::OLAP::Schema::CalculatedMember, Mondrian::OLAP::Schema::CalculatedMemberProperty, Mondrian::OLAP::Schema::CaptionExpression, Mondrian::OLAP::Schema::CellFormatter, Mondrian::OLAP::Schema::Cube, Mondrian::OLAP::Schema::CubeGrant, Mondrian::OLAP::Schema::Dimension, Mondrian::OLAP::Schema::DimensionGrant, Mondrian::OLAP::Schema::DimensionUsage, Mondrian::OLAP::Schema::Formula, Mondrian::OLAP::Schema::Hierarchy, Mondrian::OLAP::Schema::HierarchyGrant, Mondrian::OLAP::Schema::Join, Mondrian::OLAP::Schema::KeyExpression, Mondrian::OLAP::Schema::Level, Mondrian::OLAP::Schema::Measure, Mondrian::OLAP::Schema::MeasureExpression, Mondrian::OLAP::Schema::MemberFormatter, Mondrian::OLAP::Schema::MemberGrant, Mondrian::OLAP::Schema::NameExpression, Mondrian::OLAP::Schema::OrdinalExpression, Mondrian::OLAP::Schema::Parameter, Mondrian::OLAP::Schema::Property, Mondrian::OLAP::Schema::PropertyFormatter, Mondrian::OLAP::Schema::Role, Mondrian::OLAP::Schema::RoleUsage, Mondrian::OLAP::Schema::SchemaGrant, Mondrian::OLAP::Schema::Script, Mondrian::OLAP::Schema::Sql, Mondrian::OLAP::Schema::Table, Mondrian::OLAP::Schema::Union, Mondrian::OLAP::Schema::UserDefinedFunction, Mondrian::OLAP::Schema::View, Mondrian::OLAP::Schema::VirtualCube, Mondrian::OLAP::Schema::VirtualCubeDimension, Mondrian::OLAP::Schema::VirtualCubeMeasure
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(name = nil, attributes = {}, parent = nil, &block) ⇒ SchemaElement
Returns a new instance of SchemaElement.
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/mondrian/olap/schema_element.rb', line 4
def initialize(name = nil, attributes = {}, parent = nil, &block)
if name.is_a?(Hash) && attributes == {}
attributes = name
name = nil
end
@attributes = {}
if name
if self.class.content
if attributes.is_a?(Hash)
@content = name
else
@attributes[:name] = name
@content = attributes
attributes = {}
end
else
@attributes[:name] = name
end
end
@attributes.merge!(attributes)
self.class.elements.each do |element|
instance_variable_set("@#{pluralize(element)}", [])
end
if @attributes[:annotations] && self.class.elements.include?(:annotations)
annotations @attributes.delete(:annotations)
end
@xml_fragments = []
instance_eval(&block) if block
end
|
Instance Attribute Details
#xml_fragments ⇒ Object
Returns the value of attribute xml_fragments.
97
98
99
|
# File 'lib/mondrian/olap/schema_element.rb', line 97
def xml_fragments
@xml_fragments
end
|
Class Method Details
.attributes(*names) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/mondrian/olap/schema_element.rb', line 37
def self.attributes(*names)
names.each do |name|
class_eval <<-RUBY, __FILE__, __LINE__ + 1
def #{name}(*args)
if args.empty?
@attributes[:#{name}]
elsif args.size == 1
@attributes[:#{name}] = args[0]
else
raise ArgumentError, "too many arguments"
end
end
RUBY
end
end
|
.content(type = nil) ⇒ Object
91
92
93
94
95
|
# File 'lib/mondrian/olap/schema_element.rb', line 91
def self.content(type = nil)
return @content if type.nil?
attr_reader :content
@content = type
end
|
.data_dictionary_names(*names) ⇒ Object
53
54
55
56
57
|
# File 'lib/mondrian/olap/schema_element.rb', line 53
def self.data_dictionary_names(*names)
return @data_dictionary_names || [] if names.empty?
@data_dictionary_names ||= []
@data_dictionary_names.concat(names)
end
|
.elements(*names) ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/mondrian/olap/schema_element.rb', line 59
def self.elements(*names)
return @elements || [] if names.empty?
@elements ||= []
@elements.concat(names)
names.each do |name|
next if name == :xml
attr_reader pluralize(name).to_sym
class_eval <<-RUBY, __FILE__, __LINE__ + 1
def #{name}(name=nil, attributes = {}, &block)
new_element = Schema::#{camel_case(name)}.new(name, attributes, self, &block)
@#{pluralize(name)} << new_element
new_element
end
RUBY
if name == :annotations
class_eval <<-RUBY, __FILE__, __LINE__ + 1
def annotations_hash
hash = {}
@annotationss.each do |annotations|
annotations.annotations.each do |annotation|
hash[annotation.name] = annotation.content
end
end
hash
end
RUBY
end
end
end
|
Instance Method Details
#to_xml(options = {}) ⇒ Object
105
106
107
108
109
110
|
# File 'lib/mondrian/olap/schema_element.rb', line 105
def to_xml(options = {})
options[:upcase_data_dictionary] = @upcase_data_dictionary unless @upcase_data_dictionary.nil?
Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
add_to_xml(xml, options)
end.to_xml
end
|
#xml(string) ⇒ Object
98
99
100
101
102
103
|
# File 'lib/mondrian/olap/schema_element.rb', line 98
def xml(string)
string = string.strip
fragment = Nokogiri::XML::DocumentFragment.parse(string)
raise ArgumentError, "Invalid XML fragment:\n#{string}" if fragment.children.empty?
@xml_fragments << string
end
|