Class: YandexMetrica::Counter

Inherits:
Object
  • Object
show all
Defined in:
lib/yandex-metrica/counter.rb

Defined Under Namespace

Classes: Kind, Renderer, TemplateOptions

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Counter

Returns a new instance of Counter.



11
12
13
14
15
16
# 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

Instance Attribute Details

#asyncObject (readonly)

Returns the value of attribute async.



5
6
7
# File 'lib/yandex-metrica/counter.rb', line 5

def async
  @async
end

#counter_typesObject (readonly)

Returns the value of attribute counter_types.



5
6
7
# File 'lib/yandex-metrica/counter.rb', line 5

def counter_types
  @counter_types
end

#localObject (readonly)

Returns the value of attribute local.



5
6
7
# File 'lib/yandex-metrica/counter.rb', line 5

def local
  @local
end

#noscriptObject (readonly)

Returns the value of attribute noscript.



5
6
7
# File 'lib/yandex-metrica/counter.rb', line 5

def noscript
  @noscript
end

Instance Method Details

#to_sObject Also known as: render



18
19
20
21
22
23
# 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