Class: Plumb::Key
- Inherits:
-
Object
- Object
- Plumb::Key
- Defined in:
- lib/plumb/key.rb
Constant Summary collapse
- OPTIONAL_EXP =
/(\w+)(\?)?$/
Instance Attribute Summary collapse
-
#node_name ⇒ Object
readonly
Returns the value of attribute node_name.
-
#to_sym ⇒ Object
readonly
Returns the value of attribute to_sym.
Class Method Summary collapse
Instance Method Summary collapse
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(key, optional: false) ⇒ Key
constructor
A new instance of Key.
- #inspect ⇒ Object
- #optional? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(key, optional: false) ⇒ Key
Returns a new instance of Key.
13 14 15 16 17 18 19 20 21 |
# File 'lib/plumb/key.rb', line 13 def initialize(key, optional: false) key_s = key.to_s match = OPTIONAL_EXP.match(key_s) @node_name = :key @key = match[1] @to_sym = @key.to_sym @optional = !match[2].nil? ? true : optional freeze end |
Instance Attribute Details
#node_name ⇒ Object (readonly)
Returns the value of attribute node_name.
11 12 13 |
# File 'lib/plumb/key.rb', line 11 def node_name @node_name end |
#to_sym ⇒ Object (readonly)
Returns the value of attribute to_sym.
11 12 13 |
# File 'lib/plumb/key.rb', line 11 def to_sym @to_sym end |
Class Method Details
.wrap(key) ⇒ Object
7 8 9 |
# File 'lib/plumb/key.rb', line 7 def self.wrap(key) key.is_a?(Key) ? key : new(key) end |
Instance Method Details
#eql?(other) ⇒ Boolean
29 30 31 |
# File 'lib/plumb/key.rb', line 29 def eql?(other) other.hash == hash end |
#hash ⇒ Object
25 26 27 |
# File 'lib/plumb/key.rb', line 25 def hash @key.hash end |
#inspect ⇒ Object
37 38 39 |
# File 'lib/plumb/key.rb', line 37 def inspect "#{@key}#{'?' if @optional}" end |
#optional? ⇒ Boolean
33 34 35 |
# File 'lib/plumb/key.rb', line 33 def optional? @optional end |
#to_s ⇒ Object
23 |
# File 'lib/plumb/key.rb', line 23 def to_s = @key |