Class: Uberous::Loader
- Inherits:
-
Object
- Object
- Uberous::Loader
- Defined in:
- lib/uberous/uber.rb
Instance Attribute Summary collapse
-
#uber ⇒ Object
readonly
Returns the value of attribute uber.
Instance Method Summary collapse
- #hash_to_data(hash) ⇒ Object
-
#initialize(hash) ⇒ Loader
constructor
A new instance of Loader.
- #load_data ⇒ Object
- #load_error_data ⇒ Object
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
#uber ⇒ Object (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_data ⇒ Object
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_data ⇒ Object
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 |