Class: Dill::WidgetName
- Inherits:
-
String
- Object
- String
- Dill::WidgetName
- Defined in:
- lib/dill/widgets/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
-
#initialize(name) ⇒ WidgetName
constructor
Constructs the widget name.
-
#to_class(scope = Object) ⇒ Object
Returns the class for this widget name, in the given scope.
- #to_sym ⇒ Object
Constructor Details
#initialize(name) ⇒ WidgetName
Constructs the widget name.
10 11 12 13 |
# File 'lib/dill/widgets/widget_name.rb', line 10 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.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/dill/widgets/widget_name.rb', line 16 def to_class(scope = Object) const = scope.const_get(@canonical) raise TypeError, "`#{@canonical}' is not a widget in this scope" \ unless const < Widget const rescue NameError raise Missing, "couldn't find `#{@name}' widget in this scope" end |
#to_sym ⇒ Object
27 28 29 |
# File 'lib/dill/widgets/widget_name.rb', line 27 def to_sym @canonical.to_sym end |