Class: Compendium::Metric

Inherits:
Struct
  • Object
show all
Defined in:
lib/compendium/metric.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMetric

Returns a new instance of Metric.



5
6
7
8
# File 'lib/compendium/metric.rb', line 5

def initialize(*)
  super
  self.options ||= {}
end

Instance Attribute Details

#commandObject

Returns the value of attribute command

Returns:

  • (Object)

    the current value of command



2
3
4
# File 'lib/compendium/metric.rb', line 2

def command
  @command
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



2
3
4
# File 'lib/compendium/metric.rb', line 2

def name
  @name
end

#optionsObject

Returns the value of attribute options

Returns:

  • (Object)

    the current value of options



2
3
4
# File 'lib/compendium/metric.rb', line 2

def options
  @options
end

#queryObject

Returns the value of attribute query

Returns:

  • (Object)

    the current value of query



2
3
4
# File 'lib/compendium/metric.rb', line 2

def query
  @query
end

#resultObject

Returns the value of attribute result.



3
4
5
# File 'lib/compendium/metric.rb', line 3

def result
  @result
end

Instance Method Details

#ran?Boolean Also known as: has_ran?

Returns:

  • (Boolean)


18
19
20
# File 'lib/compendium/metric.rb', line 18

def ran?
  !result.nil?
end

#render(template, *options, &block) ⇒ Object



23
24
25
# File 'lib/compendium/metric.rb', line 23

def render(template, *options, &block)
  Compendium::Presenters::Metric.new(template, self, *options, &block).render
end

#run(ctx, data) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/compendium/metric.rb', line 10

def run(ctx, data)
  self.result = if condition_failed?(ctx)
    nil
  else
    command.is_a?(Symbol) ? ctx.send(command, data) : ctx.instance_exec(data, &command)
  end
end