Method: GoodData::SmallGoodZilla.create_category_filter
- Defined in:
- lib/gooddata/goodzilla/goodzilla.rb
.create_category_filter(spec, project) ⇒ Array<Hash>
Method takes a specification of the attribute filter (category filter) and returns it representation that is suitable for posting on the API. The spec is expected to be an array. First object can be an attribute (id, obj_id or directly an object). Alternativel it can be an attribute (again any representation should work). In case of attribute primary label is taken. The rest of the array are expected to be String represenation of values of particular label.
For example it could look like ['label.states.name', 'California', 'New Jersey', 'Kansas']
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/gooddata/goodzilla/goodzilla.rb', line 67 def create_category_filter(spec, project) item = project.objects(spec.first) label = item.is_a?(GoodData::Attribute) ? item.primary_label : item col = spec[1..-1].flat_map do |v| case v when Range v.to_a when Symbol [v] else [v.to_s] end end if col.first == :not values = col[1..-1].map { |v| label.find_value_uri(v) } elements = values.map { |v| "[#{v}]" }.join(', ') { expression: "[#{label.attribute.uri}] NOT IN (#{elements})" } else values = col.map { |v| label.find_value_uri(v) } elements = values.map { |v| "[#{v}]" }.join(', ') { expression: "[#{label.attribute.uri}] IN (#{elements})" } end end |