Class: Riddler::Step

Inherits:
Object
  • Object
show all
Includes:
Includeable
Defined in:
lib/riddler/step.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Includeable

#include?, #include_predicate

Constructor Details

#initialize(definition, context) ⇒ Step

Returns a new instance of Step.



23
24
25
26
# File 'lib/riddler/step.rb', line 23

def initialize definition, context
  @definition = definition
  @context = context
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



5
6
7
# File 'lib/riddler/step.rb', line 5

def context
  @context
end

#definitionObject (readonly)

Returns the value of attribute definition.



5
6
7
# File 'lib/riddler/step.rb', line 5

def definition
  @definition
end

#preview_enabledObject (readonly)

Returns the value of attribute preview_enabled.



5
6
7
# File 'lib/riddler/step.rb', line 5

def preview_enabled
  @preview_enabled
end

Class Method Details

.for(definition, context) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/riddler/step.rb', line 15

def self.for definition, context
  step_type = definition["type"]

  klass = subclasses.detect { |k| k.type == step_type }

  klass.new definition, context
end

.inherited(subclass) ⇒ Object



11
12
13
# File 'lib/riddler/step.rb', line 11

def self.inherited subclass
  self.subclasses << subclass
end

.subclassesObject



7
8
9
# File 'lib/riddler/step.rb', line 7

def self.subclasses
  @@subclasses ||= []
end

Instance Method Details

#to_hashObject



28
29
30
31
32
33
34
35
# File 'lib/riddler/step.rb', line 28

def to_hash
  {
    content_type: "step",
    type: self.class.type,
    id: definition["id"],
    name: definition["name"]
  }
end