Class: Gera::CurrencyRateDecorator
- Inherits:
-
ApplicationDecorator
- Object
- ApplicationDecorator
- Gera::CurrencyRateDecorator
- Defined in:
- app/decorators/gera/currency_rate_decorator.rb
Instance Method Summary collapse
- #comment(inverse = false) ⇒ Object
- #comment_cbr(inverse) ⇒ Object
- #comment_equal(_inverse) ⇒ Object
- #comment_exmo(inverse) ⇒ Object
- #comment_inderect(_inverse) ⇒ Object
- #comment_reverse(_inverse) ⇒ Object
- #created_at ⇒ Object
- #detailed ⇒ Object
- #external_rate ⇒ Object
- #metadata ⇒ Object
- #rate_value ⇒ Object
- #reverse_currency_rate ⇒ Object
- #short_description ⇒ Object
- #source_external_rate ⇒ Object
- #title ⇒ Object
- #tooltip ⇒ Object
Instance Method Details
#comment(inverse = false) ⇒ Object
91 92 93 94 95 96 |
# File 'app/decorators/gera/currency_rate_decorator.rb', line 91 def comment(inverse = false) return object.mode send "comment_#{object.source}", inverse rescue ActiveRecord::RecordNotFound raise "Не найдена одна из зависимых записей для #{object.id}" end |
#comment_cbr(inverse) ⇒ Object
116 117 118 119 120 121 122 123 |
# File 'app/decorators/gera/currency_rate_decorator.rb', line 116 def comment_cbr(inverse) # min_rate = Gera::ExternalRate.find object.meta.min_external_rate_id max_rate = Gera::ExternalRate.find object..max_external_rate_id # min_rate_d = ExternalRateDecorator.decorate min_rate max_rate_d = ExternalRateDecorator.decorate max_rate max_rate_d.comment inverse end |
#comment_equal(_inverse) ⇒ Object
98 99 100 |
# File 'app/decorators/gera/currency_rate_decorator.rb', line 98 def comment_equal(_inverse) 'Одинаковый тип валюты' end |
#comment_exmo(inverse) ⇒ Object
111 112 113 114 |
# File 'app/decorators/gera/currency_rate_decorator.rb', line 111 def comment_exmo(inverse) er = Gera::ExternalRate.find object..external_rate_id ExternalRateDecorator.decorate(er).comment inverse end |
#comment_inderect(_inverse) ⇒ Object
102 103 104 105 106 107 108 109 |
# File 'app/decorators/gera/currency_rate_decorator.rb', line 102 def comment_inderect(_inverse) r1 = CurrencyRateDecorator.decorate object.rate1_currency_rate r2 = CurrencyRateDecorator.decorate object.rate2_currency_rate "Через #{object..inter_cur}\n" \ "Продажа:\n" \ "#{object.rate1_currency_rate.rate_money.format} за #{object.rate1_currency_rate.cur_from}\n(#{r1.comment})\n" \ "#{object.rate2_currency_rate.rate_money.format} за #{object.rate2_currency_rate.cur_from}\n(#{r2.comment})" end |
#comment_reverse(_inverse) ⇒ Object
125 126 127 128 129 130 131 |
# File 'app/decorators/gera/currency_rate_decorator.rb', line 125 def comment_reverse(_inverse) [ "Инверсия (#{object.reverse_currency_rate.pair})", object.reverse_currency_rate.buy_rate, CurrencyRateDecorator.decorate(object.reverse_currency_rate).comment(true) ].join "\n" end |
#created_at ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'app/decorators/gera/currency_rate_decorator.rb', line 48 def created_at h.link_to h.currency_rate_path(object) do if object.created_at.present? I18n.l object.created_at, format: :long else 'время создания не известно' end end end |
#detailed ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'app/decorators/gera/currency_rate_decorator.rb', line 7 def detailed buffer = [] buffer << if object.mode_cross? 'cross' else object.rate_source.to_s # if object.rate_source.present? end buffer.join(' × ').html_safe end |
#external_rate ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/decorators/gera/currency_rate_decorator.rb', line 18 def external_rate return unless object.external_rate_id.present? er = object.external_rate buffer = if [:exmo_sell].include? mode.to_sym "#{h.humanized_rate_detailed er.sell_price} (из колонки 'продажа')" elsif [:exmo_buy].include? mode.to_sym "#{h.humanized_rate_detailed er.buy_price} (из колонки 'покупка')" elsif [:cbr_min].include? mode.to_sym "#{h.humanized_rate_detailed er.rate}<br/>(минимальный из пары #{object..rates})" elsif [:cbr_max].include? mode.to_sym "#{h.humanized_rate_detailed er.rate}<br/>(максимальный из пары #{object..rates})" else 'WTF?' end buffer = buffer + ' от ' + I18n.l(er.created_at, format: :long) h.link_to buffer.html_safe, h.external_rate_path(er) end |
#metadata ⇒ Object
87 88 89 |
# File 'app/decorators/gera/currency_rate_decorator.rb', line 87 def h.content_tag :code, object..to_json end |
#rate_value ⇒ Object
83 84 85 |
# File 'app/decorators/gera/currency_rate_decorator.rb', line 83 def rate_value h.humanized_rate_detailed object.rate_value end |
#reverse_currency_rate ⇒ Object
67 68 69 70 71 72 73 |
# File 'app/decorators/gera/currency_rate_decorator.rb', line 67 def reverse_currency_rate return '-' unless object.reverse_currency_rate_id cer = Gera::CurrencyRate.find object.reverse_currency_rate_id cerd = CurrencyRateDecorator.decorate(cer) h.link_to cerd.short_description, h.currency_rate_path(cer) end |
#short_description ⇒ Object
75 76 77 |
# File 'app/decorators/gera/currency_rate_decorator.rb', line 75 def short_description "#{title} (#{object.buy_rate}) #{comment}".html_safe end |
#source_external_rate ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'app/decorators/gera/currency_rate_decorator.rb', line 58 def source_external_rate return '-' unless object.source_external_rate_id.present? er = Gera::ExternalRate.find object.source_external_rate_id h.link_to h.external_rate_path(er) do "Источник EXMO\n#{I18n.l er.created_at, format: :long}\n#{er.buy_price}/#{er.sell_price}" end end |
#title ⇒ Object
79 80 81 |
# File 'app/decorators/gera/currency_rate_decorator.rb', line 79 def title to_s end |
#tooltip ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'app/decorators/gera/currency_rate_decorator.rb', line 39 def tooltip buffer = [] buffer << "Покупаем 1 #{object.cur_from} за #{object.rate_value} #{object.cur_to}" buffer << "Покупаем 1 #{object.currency_pair.first} за #{h.humanized_rate object.rate_value} #{object.currency_pair.second}".html_safe buffer << "Продаем 1 #{object.cur_to} за #{1.0 / object.rate_value} #{object.cur_from}" buffer = buffer.join "\n" h.simple_format(buffer).html_safe end |