module StatsHelper

  def chart_tag(opt = {})
    opt[:data] ||= {}
    opt[:data][:graph] = admin_api_stats_path(chart_data(opt))
    content_tag :div, "", opt
  end

  def chart_data(opt = {})
    data = nil
    if opt[:id].present?
      data = { opt[:id] => true }
    elsif opt[:event].present?
      data = { event: opt[:event] }
    end
    data
  end

  def graph_link_text(event)
    text = t("admin.stats.graph.#{event}")
    if text.to_s.match(/translation missing/)
      text = event
    end
    text
  end

  def budget_investments_chart_tag(opt = {})
    events = events.join(",") if events.is_a? Array
    opt[:data] ||= {}
    opt[:data][:graph] = admin_api_stats_path(budget_investments: true)
    content_tag :div, "", opt
  end

  def number_to_stats_percentage(number, options = {})
    number_to_percentage(number, { strip_insignificant_zeros: true, precision: 2 }.merge(options))
  end

  def number_with_info_tags(number, text, html_class: "")
    content_tag :p, class: "number-with-info #{html_class}".strip do
      content_tag :span, class: "content" do
        content_tag(:span, number, class: "number") + content_tag(:span, text, class: "info")
      end
    end
  end
end

module StatsHelper

  def chart_tag(opt = {})
    opt[:data] ||= {}
    opt[:data][:graph] = admin_api_stats_path(chart_data(opt))
    content_tag :div, "", opt
  end

  def chart_data(opt = {})
    data = nil
    if opt[:id].present?
      data = { opt[:id] => true }
    elsif opt[:event].present?
      data = { event: opt[:event] }
    end
    data
  end

  def graph_link_text(event)
    text = t("admin.stats.graph.#{event}")
    if text.to_s.match(/translation missing/)
      text = event
    end
    text
  end

  def budget_investments_chart_tag(opt = {})
    opt[:data] ||= {}
    opt[:data][:graph] = admin_api_stats_path(budget_investments: true)
    content_tag :div, "", opt
  end

  def number_to_stats_percentage(number, options = {})
    number_to_percentage(number, { strip_insignificant_zeros: true, precision: 2 }.merge(options))
  end

  def number_with_info_tags(number, text, html_class: "")
    content_tag :p, class: "number-with-info #{html_class}".strip do
      content_tag :span, class: "content" do
        content_tag(:span, number, class: "number") + content_tag(:span, text, class: "info")
      end
    end
  end
end

Remove line auto-assigning a variable to `nil`
Remove line auto-assigning a variable to `nil`

This is one of the most strange behaviours in ruby: if a variable
doesn't exist, assigning to itself will return `nil`.

So a line like:

mdmkdfm = ooops if mdmkdfm.respond_to?(:uiqpior)

Surprisingly will not raise any errors: the nonexistent `mdmkdfm`
variable will be evaluated to `nil`, `mdmkdfm.respond_to?(:uiqpior)`
will evaluate to `nil.respond_to?(:uiqpior)`, which will return `false`,
and then the line will be evaluated as `mdmkdfm = ooops if false`, which
will return `nil`.

Maybe in the future Ruby will change this behaviour. We hope CONSUL is
now in better shape if that ever happens :).
