Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/swivel.rb
Instance Method Summary collapse
-
#dashify ⇒ Object
Returns the string with ‘_’ translated to ‘-’ ‘data_set’.dashify # => “data-set”.
-
#numeric? ⇒ Boolean
Returns true if the string looks numeric ‘1283.22’.numeric? # => true ‘howdy’.numeric? # => false.
-
#to_xml_tag ⇒ Object
Returns a string as a suitable xml tag by underscoring and dashifying.
-
#undashify ⇒ Object
Returns the string with ‘-’ translated to ‘_’ ‘data-set’.undashify # => “data_set”.
Instance Method Details
#dashify ⇒ Object
Returns the string with ‘_’ translated to ‘-’
'data_set'.dashify # => "data-set"
34 35 36 |
# File 'lib/swivel.rb', line 34 def dashify self.tr('_', '-') end |
#numeric? ⇒ Boolean
Returns true if the string looks numeric
'1283.22'.numeric? # => true
'howdy'.numeric? # => false
25 26 27 28 29 |
# File 'lib/swivel.rb', line 25 def numeric? # work around the bug in ruby ^ regexp matching string_sans_newlines = self.gsub(/\r|\n/, ' ') (string_sans_newlines =~ /^-?\d+(\.\d+|\d*)$/) != nil end |
#to_xml_tag ⇒ Object
Returns a string as a suitable xml tag by underscoring and dashifying. Not perfect, but serves its purpose.
'DataSet'.to_xml_tag # => "data-set"
49 50 51 |
# File 'lib/swivel.rb', line 49 def to_xml_tag self.underscore.dasherize end |
#undashify ⇒ Object
Returns the string with ‘-’ translated to ‘_’
'data-set'.undashify # => "data_set"
41 42 43 |
# File 'lib/swivel.rb', line 41 def undashify self.tr('-', '_') end |