Class: GoodData::Attribute
- Inherits:
-
MdObject
- Object
- Rest::Object
- Rest::Resource
- MdObject
- GoodData::Attribute
- Includes:
- Mixin::IsAttribute
- Defined in:
- lib/gooddata/models/metadata/attribute.rb
Constant Summary collapse
- ATTRIBUTE_BASE_AGGREGATIONS =
[:count]
Constants inherited from MdObject
MdObject::IDENTIFIERS_CFG, MdObject::MD_OBJ_CTG
Constants included from Mixin::MdIdToUri
Mixin::MdIdToUri::IDENTIFIERS_CFG
Constants included from Mixin::MdObjectIndexer
Mixin::MdObjectIndexer::MD_OBJ_CTG
Instance Attribute Summary
Attributes inherited from Rest::Object
Class Method Summary collapse
-
.all(options = { :client => GoodData.connection, :project => GoodData.project }) ⇒ Array<GoodData::MdObject> | Array<Hash>
Method intended to get all objects of that type in a specified project.
-
.find_element_value(stuff, opts = { :project => GoodData.project }) ⇒ String
Finds the value of an atribute and gives you the textual form for the label that is acquired by calling primary_label method.
Instance Method Summary collapse
-
#create_metric(options = {}) ⇒ GoodData::Metric
(also: #create_measure)
Creates the basic count metric with the attribute used.
-
#date_attribute? ⇒ Boolean
Tells you if an attribute is a date dimension.
- #dimension ⇒ Object
-
#display_forms ⇒ Array<GoodData::Label>
(also: #labels)
Returns the labels of an attribute.
- #drill_down(attribute) ⇒ Object
-
#label_by_name(name) ⇒ GoodData::Label
Allows to search in attribute labels by name.
-
#primary_display_form ⇒ GoodData::Label
(also: #primary_label)
Returns the first display form which is the primary one.
-
#values ⇒ Array
Returns all values for all labels.
-
#values_for(element_id) ⇒ Array
For an element id find values (titles) for all display forms.
Methods included from Mixin::IsAttribute
Methods inherited from MdObject
#==, #add_tag, #browser_uri, #delete, #deprecated, #deprecated=, find_replaceable_values, #initialize, #listed?, #project, #reload!, #remove_tag, replace, #replace, #replace!, replace_bracketed, replace_quoted, #save, #save_as, #tag_set, #unlisted, #unlisted=, #validate
Methods included from Mixin::MdIdToUri
Methods included from Mixin::MdObjectIndexer
Methods included from Mixin::MdObjectQuery
#all, #dependency, #dependency?, #query, #usedby, #usedby?, #using, #using?
Methods included from Mixin::MdFinders
#find_by_identifier, #find_by_tag, #find_by_title, #find_first_by_identifier, #find_first_by_title
Methods included from Mixin::MdObjId
Methods included from Mixin::MdGrantees
#change_permission, #grant, #grantees, #revoke
Methods included from Mixin::MdRelations
#dependency, #dependency?, #usedby, #usedby?, #using, #using?
Methods included from Mixin::ObjId
Methods included from Mixin::Links
Methods inherited from Rest::Resource
Methods inherited from Rest::Object
client, default_client, #initialize, #saved?
Methods included from Mixin::DataPropertyReader
Methods included from Mixin::DataPropertyWriter
Methods included from Mixin::MetaPropertyReader
Methods included from Mixin::MetaPropertyWriter
Methods included from Mixin::MetaGetter
Methods included from Mixin::DataGetter
Methods included from Mixin::RootKeyGetter
Methods included from Mixin::ContentGetter
Constructor Details
This class inherits a constructor from GoodData::MdObject
Class Method Details
.all(options = { :client => GoodData.connection, :project => GoodData.project }) ⇒ Array<GoodData::MdObject> | Array<Hash>
Method intended to get all objects of that type in a specified project
25 26 27 |
# File 'lib/gooddata/models/metadata/attribute.rb', line 25 def all( = { :client => GoodData.connection, :project => GoodData.project }) query('attribute', Attribute, ) end |
.find_element_value(stuff, opts = { :project => GoodData.project }) ⇒ String
Finds the value of an atribute and gives you the textual form for the label that is acquired by calling primary_label method
33 34 35 36 37 |
# File 'lib/gooddata/models/metadata/attribute.rb', line 33 def find_element_value(stuff, opts = { :project => GoodData.project }) stuff.scan(%r{([^\[\]]*)\/elements\?id=(\d+)}).pmap do |a, id| opts[:project].attributes(a).primary_label.find_element_value(id.to_i) end.first end |
Instance Method Details
#create_metric(options = {}) ⇒ GoodData::Metric Also known as: create_measure
Creates the basic count metric with the attribute used. If you need to compute the attribute on a different dataset you can specify that in params. The metric created is not saved.
100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/gooddata/models/metadata/attribute.rb', line 100 def create_metric( = {}) an_attribute = [:attribute] a_type = [:type] || :count fail "Suggested aggreagtion function (#{a_type}) does not exist for base metric created out of attribute. You can use only one of #{ATTRIBUTE_BASE_AGGREGATIONS.map { |x| ':' + x.to_s }.join(',')}" unless ATTRIBUTE_BASE_AGGREGATIONS.include?(a_type) a_title = [:title] || "#{a_type} of #{title}" if an_attribute project.create_metric("SELECT #{a_type.to_s.upcase}([#{uri}], [#{an_attribute.uri}])", title: a_title, extended_notation: false) else project.create_metric("SELECT #{a_type.to_s.upcase}([#{uri}])", title: a_title, extended_notation: false) end end |
#date_attribute? ⇒ Boolean
Tells you if an attribute is a date dimension. This happens by inspecting an identifier if it conforms to a particular scheme.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/gooddata/models/metadata/attribute.rb', line 63 def date_attribute? things = [ 'week', 'euweek.in.year', 'day.in.week', 'day.in.month', 'day.in.quarter', 'day.in.euweek', 'date', 'quarter.in.year', 'week.in.year', 'day.in.year', 'month', 'quarter', 'month.in.quarter', 'week.in.quarter', 'year', 'euweek', 'euweek.in.quarter', 'month.in.year' ] potential_id = identifier.split('.')[1..-1].join('.') things.include?(potential_id) ? true : false end |
#dimension ⇒ Object
53 54 55 56 57 |
# File 'lib/gooddata/models/metadata/attribute.rb', line 53 def dimension uri = content['dimension'] return nil if uri.nil? GoodData::Dimension[uri, client: client, project: project] end |
#display_forms ⇒ Array<GoodData::Label> Also known as: labels
Returns the labels of an attribute
48 49 50 |
# File 'lib/gooddata/models/metadata/attribute.rb', line 48 def display_forms content['displayForms'].pmap { |df| project.labels(df['meta']['uri']) } end |
#drill_down(attribute) ⇒ Object
40 41 42 43 44 |
# File 'lib/gooddata/models/metadata/attribute.rb', line 40 def drill_down(attribute) attribute = Attribute[attribute, client: client, project: project] content['drillDownStepAttributeDF'] = attribute.primary_label.['uri'] save end |
#label_by_name(name) ⇒ GoodData::Label
Allows to search in attribute labels by name. It uses the string as a basis for regexp and tries to match either a title or an identifier. Returns first match.
136 137 138 |
# File 'lib/gooddata/models/metadata/attribute.rb', line 136 def label_by_name(name) labels.find { |label| label.title =~ /#{name}/ || label.identifier =~ /#{name}/ } end |
#primary_display_form ⇒ GoodData::Label Also known as: primary_label
Returns the first display form which is the primary one
90 91 92 |
# File 'lib/gooddata/models/metadata/attribute.rb', line 90 def primary_display_form labels.first end |
#values ⇒ Array
Returns all values for all labels. This is for inspection purposes only since obviously there can be huge number of elements.
128 129 130 131 |
# File 'lib/gooddata/models/metadata/attribute.rb', line 128 def values results = labels.map(&:values) results.first.zip(*results[1..-1]) end |
#values_for(element_id) ⇒ Array
For an element id find values (titles) for all display forms. Element id can be given as both number id or URI as a string beginning with /
117 118 119 120 121 122 |
# File 'lib/gooddata/models/metadata/attribute.rb', line 117 def values_for(element_id) # element_id = element_id.is_a?(String) ? element_id.match(/\?id=(\d)/)[1] : element_id labels.pmap do |label| label.find_element_value(element_id) end end |