Class: Uberous::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/uberous/uber.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Loader

Returns a new instance of Loader.



69
70
71
72
73
74
75
76
77
# File 'lib/uberous/uber.rb', line 69

def initialize(hash)
  uber_hash = hash['uber']
  @uber_data_hashes = uber_hash.fetch('data', [])
  @uber_error_data_hashes = uber_hash.fetch('error', [])
  @uber = Uber.new([], [], uber_hash['version'])

  load_data
  load_error_data
end

Instance Attribute Details

#uberObject (readonly)

Returns the value of attribute uber.



68
69
70
# File 'lib/uberous/uber.rb', line 68

def uber
  @uber
end

Instance Method Details

#hash_to_data(hash) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/uberous/uber.rb', line 91

def hash_to_data(hash)
  data_hash = {}
  hash.each do |k, v|
    data_hash[(k.to_sym rescue k)] = v # symbolize_keys
  end
  child_data_hashes = data_hash.delete(:data) || []
  data = Data.new(data_hash)
  child_data_hashes.each do |child_data_hash|
    data.add_data(hash_to_data(child_data_hash))
  end
  data
end

#load_dataObject



79
80
81
82
83
# File 'lib/uberous/uber.rb', line 79

def load_data
  @uber_data_hashes.each do |uber_data_hash|
    @uber.add_data(hash_to_data(uber_data_hash))
  end
end

#load_error_dataObject



85
86
87
88
89
# File 'lib/uberous/uber.rb', line 85

def load_error_data
  @uber_error_data_hashes.each do |uber_error_data_hash|
    @uber.add_data(hash_to_data(uber_error_data_hash))
  end
end