Class: TFSGraph::Normalizer

Inherits:
Object
  • Object
show all
Defined in:
lib/tfs_graph/normalizer.rb

Class Method Summary collapse

Class Method Details

.normalize(item) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/tfs_graph/normalizer.rb', line 8

def normalize(item)
  representation = {}
  schema.each do |key, lookup|

    if lookup[:key].present?  # for keys that pull data from other sources
      value = item.send lookup[:key]
      value = lookup[:converter].call(value) if lookup[:converter].present?
    else
      value = lookup[:default]
    end

    representation[key] = value
  end
  representation
end

.normalize_many(data) ⇒ Object



4
5
6
# File 'lib/tfs_graph/normalizer.rb', line 4

def normalize_many(data)
  data.map {|item| normalize item }
end