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) ⇒ 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_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
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/gooddata/models/from_wire.rb', line 14 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)) end end |
.from_wire(wire_model) ⇒ GoodData::Model::ProjectBlueprint
Entry method for converting information about project mode from wire format into an internal blueprint representation
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/gooddata/models/from_wire.rb', line 30 def self.from_wire(wire_model) model = wire_model['projectModelView']['model']['projectModel'] datasets = model['datasets'] || [] dims = model['dateDimensions'] || [] ProjectBlueprint.new( 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
57 58 59 60 |
# File 'lib/gooddata/models/from_wire.rb', line 57 def self.parse_anchor(stuff) anchor = stuff['dataset']['anchor']['attribute'] parse_attribute(anchor, :anchor) end |
.parse_attribute(attribute, type = :attribute) ⇒ Object
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 96 |
# File 'lib/gooddata/models/from_wire.rb', line 62 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 end [attribute] + pl + rl end |
.parse_attributes(stuff) ⇒ Hash
Converts attrbutes from wire format into an internal blueprint representation
45 46 47 48 49 50 51 |
# File 'lib/gooddata/models/from_wire.rb', line 45 def self.parse_attributes(stuff) dataset = stuff['dataset'] attributes = dataset['attributes'] || [] attributes.mapcat do |a| parse_attribute(a['attribute']) end end |
.parse_date_dimensions(date_dim) ⇒ Hash
Converts date dimensions from wire format into an internal blueprint representation
102 103 104 105 106 107 108 |
# File 'lib/gooddata/models/from_wire.rb', line 102 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'] end end |
.parse_facts(stuff) ⇒ Hash
Converts facts from wire format into an internal blueprint representation
114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/gooddata/models/from_wire.rb', line 114 def self.parse_facts(stuff) facts = stuff['dataset']['facts'] || [] facts.map do |fact| {}.tap do |f| f[:type] = fact['fact']['identifier'] =~ /^dt\./ ? :date_fact : :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 end end end |
.parse_label(attribute, label, type) ⇒ Hash
Converts label from wire format into an internal blueprint representation
132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/gooddata/models/from_wire.rb', line 132 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
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/gooddata/models/from_wire.rb', line 149 def self.parse_references(dataset) references = dataset['dataset']['references'] || [] references.map do |ref| if ref =~ /^dataset\./ { :type => :reference, :dataset => ref } else { :type => :date, :dataset => ref } end end end |