Class: Net::DND::UserSpec
- Inherits:
-
Object
- Object
- Net::DND::UserSpec
- Defined in:
- lib/net/dnd/user_spec.rb
Overview
Once a string specifier is passed into the constructer method, it’s stored and then matched against one of several patterns to determine it’s type. This type is then used to choose the output format of the specifier, when the instantiated class object is coerced back to a string.
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(specifier) ⇒ UserSpec
constructor
Construct our specifier object and set its type attribute.
-
#inspect ⇒ Object
Inspection string for the specifier object.
-
#to_s ⇒ Object
Output the correct ‘string’ format for our specifier.
Constructor Details
#initialize(specifier) ⇒ UserSpec
Construct our specifier object and set its type attribute.
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/net/dnd/user_spec.rb', line 20 def initialize(specifier) @spec = specifier.to_s @type = case @spec.downcase when /^\d+$/ :uid when /^z\d+$/ :did when /^\d+[a-z]\d*$/ :did else :name end end |
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
16 17 18 |
# File 'lib/net/dnd/user_spec.rb', line 16 def type @type end |
Instance Method Details
#inspect ⇒ Object
Inspection string for the specifier object.
51 52 53 |
# File 'lib/net/dnd/user_spec.rb', line 51 def inspect "#<#{self.class} specifier=\"#{@spec}\" type=:#{@type}>" end |
#to_s ⇒ Object
Output the correct ‘string’ format for our specifier. The :uid and :did types have special characters prepended to their value, so that they are correctly formatted for use in a DND connection/protocol lookup command.
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/net/dnd/user_spec.rb', line 38 def to_s case @type when :uid "##{@spec}" when :did "#*#{@spec}" else @spec end end |