class YandexMetrica::Counter
Attributes
async[R]
counter_types[R]
local[R]
noscript[R]
Public Class Methods
new(args = {})
click to toggle source
# File lib/yandex-metrica/counter.rb, line 11 def initialize(args = {}) @options_types ||= [] prepare_view_options(args) append_counter_types(args) @options_renderer = YandexMetrica::Counter::Renderer.new(@options_types) end
Public Instance Methods
to_s()
click to toggle source
# File lib/yandex-metrica/counter.rb, line 18 def to_s return if YM.invalid_counter? template_name = @async ? "async" : "sync" @template ||= ::ERB.new ::File.read ::File.expand_path("../templates/#{template_name}.erb", __FILE__) @template.result(template_options.instance_eval { binding }).html_safe end
Also aliased as: render
Protected Instance Methods
append_counter_types(args = {})
click to toggle source
# File lib/yandex-metrica/counter.rb, line 44 def append_counter_types(args = {}) args = YM.options.merge(args) @options_types << Kind.new(:id, YM.counter) args.each do |k,v| @options_types << Kind.new(k,v) end end
prepare_view_options(args)
click to toggle source
# File lib/yandex-metrica/counter.rb, line 36 def prepare_view_options(args) @local = args.delete(:local) || false @async = true @async = args.delete(:async) if args.include? :async @noscript = true @noscript = args.delete(:noscript) if args.include? :noscript end
template_options()
click to toggle source
# File lib/yandex-metrica/counter.rb, line 28 def template_options TemplateOptions.new({ counter_name: "yaCounter#{YM.counter}", counter_options: @options_renderer.to_s, noscript: @noscript }) end