Class: MorseCode::Base
- Inherits:
-
Object
show all
- Defined in:
- lib/morse_code/base.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(word = '', namespace = '') ⇒ Base
Returns a new instance of Base.
14
15
16
17
|
# File 'lib/morse_code/base.rb', line 14
def initialize(word = '', namespace = '')
@word = word
@namespace = namespace
end
|
Instance Attribute Details
#namespace ⇒ Object
Returns the value of attribute namespace.
12
13
14
|
# File 'lib/morse_code/base.rb', line 12
def namespace
@namespace
end
|
#word ⇒ Object
Returns the value of attribute word.
12
13
14
|
# File 'lib/morse_code/base.rb', line 12
def word
@word
end
|
Class Method Details
.inherited(subclass) ⇒ Object
7
8
9
10
|
# File 'lib/morse_code/base.rb', line 7
def self.inherited(subclass)
@@subclasses ||= []
@@subclasses << subclass
end
|
Instance Method Details
#call ⇒ Object
23
24
25
26
|
# File 'lib/morse_code/base.rb', line 23
def call
return supported_class.new(word).call if supported_class
word
end
|
#supported? ⇒ Boolean
19
20
21
|
# File 'lib/morse_code/base.rb', line 19
def supported?
raise MorseCode::NotImplementedError, 'Subclass must override supported? method'
end
|
#supported_class ⇒ Object
28
29
30
|
# File 'lib/morse_code/base.rb', line 28
def supported_class
supported_classes.detect { |clazz| clazz.name.start_with?(namespace) }
end
|
#supported_classes ⇒ Object
32
33
34
35
36
|
# File 'lib/morse_code/base.rb', line 32
def supported_classes
supported_classes = Array(@@subclasses).select { |subclass| subclass.new(word).supported? }
puts "[WARING] Not Classs can support this #{word}!" if supported_classes.empty?
supported_classes
end
|