Module: Yogo::Data::DefaultMethods::ClassMethods

Defined in:
lib/yogo/data/default_methods.rb

Instance Method Summary collapse

Instance Method Details

#labeled_propertiesObject



29
30
31
# File 'lib/yogo/data/default_methods.rb', line 29

def labeled_properties
  properties.select{|p| !p.options['label'].nil? }
end

#parse_json(body) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/yogo/data/default_methods.rb', line 15

def parse_json(body)
  json = JSON.parse(body)
  props = labeled_properties
  ret = {}
  # I don't think we care about other items passed back.
  json['data'].each_pair do |key,value|
    property = props.select{|p| p.options['label'] == key || p.name.to_s == key}
    return nil unless property.length == 1
    # raise Exception, "There shouldn't be more the one property with the same label"
    ret[property.first.name] = value
  end
  return ret
end

#schemaObject



11
12
13
# File 'lib/yogo/data/default_methods.rb', line 11

def schema
  class_variable_get(:@@schema)
end

#unlabeled_propertiesObject



33
34
35
# File 'lib/yogo/data/default_methods.rb', line 33

def unlabeled_properties
  properties.select{|p| p.options['label'].nil? }        
end