Module: Traffic
- Defined in:
- lib/traffic.rb,
lib/traffic/info.rb,
lib/traffic/version.rb,
lib/traffic/provider.rb,
lib/traffic/providers/anwb.rb,
lib/traffic/providers/file_index.rb
Defined Under Namespace
Modules: Providers Classes: Info, InfoItem
Constant Summary collapse
- MAIN_ATTRIBUTES =
[:timestamp, :count, :size, :traffic]
- ITEM_ATTRIBUTES =
[:road, :from, :to, :from_location, :to_location, :location, :length, :description, :cause, :status]
- VERSION =
"0.0.6"
Class Method Summary collapse
Class Method Details
.from(provider_name, archived_data = nil) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/traffic.rb', line 6 def self.from(provider_name, archived_data=nil) provider = Provider(provider_name).new(archived_data) info = Info.new MAIN_ATTRIBUTES.each do |attr| if provider.respond_to?(attr) info.send("#{attr}=", provider.send(attr)) else raise "attribute missing: #{attr}. the selected provider ('#{provider_name}') does not supply all required attributes" end end provider.each_item do |item| info_item = InfoItem.new ITEM_ATTRIBUTES.each do |attr| if item.respond_to?(attr) info_item.send("#{attr}=", item.send(attr)) else raise "attribute missing: #{attr}. the selected provider item ('#{provider_name}') does not supply all required attributes" end end info.items << info_item end info end |