Class: String

Inherits:
Object show all
Defined in:
vendor/bundler/ruby/3.1.0/bundler/gems/sxp.rb-7133e42f43bb/lib/sxp/extensions.rb,
vendor/bundler/ruby/3.1.0/bundler/gems/rdf-4f45c0ed29ed/lib/rdf/extensions.rb,
vendor/bundler/ruby/3.1.0/bundler/gems/rdf-rdfa-9522e3361b98/lib/rdf/rdfa/patches/string_hacks.rb

Overview

Extensions for Ruby's String class.

Instance Method Summary collapse

Instance Method Details

#align_leftObject

Trim beginning of each line by the amount of indentation in the first line



3
4
5
6
7
8
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-rdfa-9522e3361b98/lib/rdf/rdfa/patches/string_hacks.rb', line 3

def align_left
  str = self.sub(/^\s*$/, '')  # Remove leading newline
  str = str[1..-1] if str[0,1] == "\n"
  ws = str.match(/^(\s*)\S/m) ? $1 : ''
  str.gsub(/^#{ws}/m, '')
end

#match?(*args) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-4f45c0ed29ed/lib/rdf/extensions.rb', line 18

def match?(*args)
  !match(*args).nil?
end

#to_sxp(**options) ⇒ String

Returns the SXP representation of this object. Uses SPARQL-like escaping.

Returns:



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/sxp.rb-7133e42f43bb/lib/sxp/extensions.rb', line 61

def to_sxp(**options)
  buffer = ""
  each_char do |u|
    buffer << case u.ord
    when (0x00..0x07) then sprintf("\\u%04X", u.ord)
    when (0x08)       then '\b'
    when (0x09)       then '\t'
    when (0x0A)       then '\n'
    when (0x0C)       then '\f'
    when (0x0D)       then '\r'
    when (0x0E..0x1F) then sprintf("\\u%04X", u.ord)
    when (0x22)       then '\"'
    when (0x5C)       then '\\\\'
    when (0x7F)       then sprintf("\\u%04X", u.ord)
    else u.chr
    end
  end
  '"' + buffer + '"'
end