Class: Cucumber::Salad::WidgetName

Inherits:
String
  • Object
show all
Defined in:
lib/cucumber/salad/widget_name.rb

Overview

The name of a widget in a format-independent representation.

Constant Summary collapse

CAMEL_CASE_FORMAT =
/\A([A-Z][a-z]*)+\Z/
SNAKE_CASE_FORMAT =
/\A\w+\Z/

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ WidgetName

Constructs the widget name.

Parameters:

  • name (String, Symbol)

    the name of the widget in primitive form



11
12
13
14
# File 'lib/cucumber/salad/widget_name.rb', line 11

def initialize(name)
  @name      = name
  @canonical = canonical(@name)
end

Instance Method Details

#to_class(scope = Object) ⇒ Object

Returns the class for this widget name, in the given scope.



17
18
19
20
21
22
23
24
25
26
# File 'lib/cucumber/salad/widget_name.rb', line 17

def to_class(scope = Object)
  const = scope.const_get(@canonical)

  raise TypeError, "`#{@canonical}' is not a widget in this scope" \
    unless const < Widgets::Widget

  const
rescue NameError
  raise Missing, "couldn't find `#{@name}' widget in this scope"
end

#to_symObject



28
29
30
# File 'lib/cucumber/salad/widget_name.rb', line 28

def to_sym
  @canonical.to_sym
end