Class: ODDB::State::Drugs::PriceHistory

Inherits:
Global show all
Defined in:
src/state/drugs/price_history.rb

Defined Under Namespace

Classes: PriceChange, PriceChanges

Constant Summary

VIEW =
View::Drugs::PriceHistory

Constants inherited from Global

HOME_STATE, ZONE, ZONE_NAVIGATION

Constants inherited from Global

DIRECT_EVENT, GLOBAL_MAP, HOME_STATE, LIMITED, PRINT_STATES, READONLY_STATES, RESOLVE_STATES, REVERSE_MAP, VIEW, ZONE_NAVIGATION

Constants included from UmlautSort

FILTER_PAIRS

Instance Method Summary (collapse)

Methods inherited from Global

#limit_state

Methods inherited from Global

#_search_drugs, #_search_drugs_state, #_trigger, #add_to_interaction_basket, #allowed?, #atc_chooser, #checkout, #clear_interaction_basket, #creditable?, #direct_request_path, #doctorlist, #download, #export_csv, #extend, #fachinfo, #feedbacks, #help_navigation, #home_navigation, #home_state, #hospitallist, #interaction_basket, #limit_state, #limited?, #logout, #navigation, #notify, #password_reset, #paypal_return, #powerlink, #print, #proceed_download, #proceed_poweruser, #resolve, #resolve_state, #rss, #search, #show, #snapback_event, #sort, #sponsorlink, #suggest_address, #switch, #unique_email, #user_input, #user_navigation, #ywesee_contact, #zone_navigation, #zones

Methods included from Admin::LoginMethods

#autologin, #login

Methods included from UmlautSort

#sort_model, #umlaut_filter

Instance Method Details

- (Object) init



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'src/state/drugs/price_history.rb', line 22

def init
  @model = PriceChanges.new
  if pack = (pointer = @session.user_input(:pointer)) \
    && pointer.resolve(@session.app)
    @model.package = pack
    dates = {}
    pack.prices.each do |key, prices|
      previous = nil
      prices.sort_by do |price| price.valid_from end.each do |price|
        date = price.valid_from
        change = (dates[date] ||= PriceChange.new(date))
        change.send("#{key}=", price)
        if price.credits && previous && (pprice = previous.send(key)) \
          && pprice.credits
          change.send "percent_#{key}=", (price - pprice) / pprice * 100
        end
        previous = change
      end
    end
    @model.concat dates.values
  end
end