Module: GoodData::Model::FromWire
- Defined in:
- lib/gooddata/models/from_wire.rb
Class Method Summary collapse
-
.dataset_from_wire(dataset) ⇒ Hash
Converts dataset from wire format into an internal blueprint representation.
-
.from_wire(wire_model, options = {}) ⇒ GoodData::Model::ProjectBlueprint
Entry method for converting information about project mode from wire format into an internal blueprint representation.
-
.parse_anchor(stuff) ⇒ Hash
Converts anchor from wire format into an internal blueprint representation.
- .parse_attribute(attribute, type = :attribute) ⇒ Object
-
.parse_attributes(stuff) ⇒ Hash
Converts attrbutes from wire format into an internal blueprint representation.
-
.parse_bridges(dataset) ⇒ Hash
Converts bridges from wire format into an internal blueprint representation.
-
.parse_date_dimensions(date_dim) ⇒ Hash
Converts date dimensions from wire format into an internal blueprint representation.
-
.parse_facts(stuff) ⇒ Hash
Converts facts from wire format into an internal blueprint representation.
-
.parse_label(attribute, label, type) ⇒ Hash
Converts label from wire format into an internal blueprint representation.
-
.parse_references(dataset) ⇒ Hash
Converts label from wire format into an internal blueprint representation.
Class Method Details
.dataset_from_wire(dataset) ⇒ Hash
Converts dataset from wire format into an internal blueprint representation
12 13 14 15 16 17 18 19 20 |
# File 'lib/gooddata/models/from_wire.rb', line 12 def self.dataset_from_wire(dataset) {}.tap do |d| id = dataset['dataset']['identifier'] d[:type] = :dataset d[:title] = dataset['dataset']['title'] d[:id] = id d[:columns] = (parse_anchor(dataset) + parse_attributes(dataset) + parse_facts(dataset) + parse_references(dataset) + parse_bridges(dataset)) end end |
.from_wire(wire_model, options = {}) ⇒ GoodData::Model::ProjectBlueprint
Entry method for converting information about project mode from wire format into an internal blueprint representation
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/gooddata/models/from_wire.rb', line 27 def self.from_wire(wire_model, = {}) model = wire_model['projectModelView']['model']['projectModel'] datasets = model['datasets'] || [] dims = model['dateDimensions'] || [] ProjectBlueprint.new( include_ca: [:include_ca], datasets: datasets.map { |ds| dataset_from_wire(ds) }, date_dimensions: dims.map { |dd| parse_date_dimensions(dd) } ) end |
.parse_anchor(stuff) ⇒ Hash
Converts anchor from wire format into an internal blueprint representation
54 55 56 57 |
# File 'lib/gooddata/models/from_wire.rb', line 54 def self.parse_anchor(stuff) anchor = stuff['dataset']['anchor']['attribute'] parse_attribute(anchor, :anchor) end |
.parse_attribute(attribute, type = :attribute) ⇒ 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 90 91 92 93 94 95 |
# File 'lib/gooddata/models/from_wire.rb', line 59 def self.parse_attribute(attribute, type = :attribute) labels = attribute['labels'] || [] default_label_id = attribute['defaultLabel'] default_label = labels.find { |l| l['label']['identifier'] == default_label_id } || labels.first regular_labels = labels - [default_label] pl = default_label.nil? ? [] : [parse_label(attribute, default_label, :default_label)] rl = regular_labels.map do |label| parse_label(attribute, label, :label) end attr_sort_order = attribute['sortOrder']['attributeSortOrder'] if attribute['sortOrder'] attribute = {}.tap do |a| a[:type] = type a[:id] = attribute['identifier'] a[:title] = attribute['title'] a[:description] = attribute['description'] a[:folder] = attribute['folder'] if attr_sort_order a[:order_by] = "#{attr_sort_order['label']} - #{attr_sort_order['direction']}" end if attribute['grain'] a[:grain] = attribute['grain'].map do |g| case g.keys.first.to_sym when :dateDimension { date: g.values.first } else Helpers.symbolize_keys(g) end end end attribute['relations'] && a[:relations] = attribute['relations'] end [attribute] + pl + rl end |
.parse_attributes(stuff) ⇒ Hash
Converts attrbutes from wire format into an internal blueprint representation
42 43 44 45 46 47 48 |
# File 'lib/gooddata/models/from_wire.rb', line 42 def self.parse_attributes(stuff) dataset = stuff['dataset'] attributes = dataset['attributes'] || [] attributes.mapcat do |a| parse_attribute(a['attribute']) end end |
.parse_bridges(dataset) ⇒ Hash
Converts bridges from wire format into an internal blueprint representation
167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/gooddata/models/from_wire.rb', line 167 def self.parse_bridges(dataset) references = !dataset['dataset'].nil? && !dataset['dataset']['bridges'].nil? ? dataset['dataset']['bridges'] : [] references = !dataset['dateDimension'].nil? && !dataset['dateDimension']['bridges'].nil? ? dataset['dateDimension']['bridges'] : references references.map do |ref| if ref =~ /^dataset\./ { :type => :bridge, :dataset => ref } else {} end end end |
.parse_date_dimensions(date_dim) ⇒ Hash
Converts date dimensions from wire format into an internal blueprint representation
101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/gooddata/models/from_wire.rb', line 101 def self.parse_date_dimensions(date_dim) {}.tap do |d| d[:type] = :date_dimension d[:id] = date_dim['dateDimension']['name'] d[:title] = date_dim['dateDimension']['title'] d[:urn] = date_dim['dateDimension']['urn'] d[:identifier_prefix] = date_dim['dateDimension']['identifierPrefix'] d[:identifier] = date_dim['dateDimension']['identifier'] if date_dim['dateDimension']['identifier'] d[:columns] = parse_bridges(date_dim) end end |
.parse_facts(stuff) ⇒ Hash
Converts facts from wire format into an internal blueprint representation
117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/gooddata/models/from_wire.rb', line 117 def self.parse_facts(stuff) facts = stuff['dataset']['facts'] || [] facts.map do |fact| {}.tap do |f| f[:type] = resolve_fact_type(fact) f[:id] = fact['fact']['identifier'] f[:title] = fact['fact']['title'] f[:description] = fact['fact']['description'] if fact['fact']['description'] f[:folder] = fact['fact']['folder'] f[:gd_data_type] = fact['fact']['dataType'] || GoodData::Model::DEFAULT_FACT_DATATYPE f[:restricted] = fact['fact']['restricted'] if fact['fact']['restricted'] end end end |
.parse_label(attribute, label, type) ⇒ Hash
Converts label from wire format into an internal blueprint representation
136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/gooddata/models/from_wire.rb', line 136 def self.parse_label(attribute, label, type) {}.tap do |l| l[:type] = :label l[:id] = label['label']['identifier'] l[:reference] = attribute['identifier'] l[:title] = label['label']['title'] l[:gd_data_type] = label['label']['dataType'] || GoodData::Model::DEFAULT_ATTRIBUTE_DATATYPE l[:gd_type] = label['label']['type'] || GoodData::Model::DEFAULT_TYPE l[:default_label] = true if type == :default_label end end |
.parse_references(dataset) ⇒ Hash
Converts label from wire format into an internal blueprint representation
153 154 155 156 157 158 159 160 161 |
# File 'lib/gooddata/models/from_wire.rb', line 153 def self.parse_references(dataset) references = dataset['dataset']['references'] || [] references.map do |ref| { :type => ref =~ /^dataset\./ ? :reference : :date, :dataset => ref } end end |