Class: String

Inherits:
Object show all
Defined in:
lib/other.rb

Instance Method Summary collapse

Instance Method Details

#capitalize_first_letterObject



128
129
130
# File 'lib/other.rb', line 128

def capitalize_first_letter
  self.sub(/^(.)/) { $1.capitalize }
end

#coerce(a) ⇒ Object

nodoc#



203
204
205
# File 'lib/other.rb', line 203

def coerce a  #nodoc#
 nil  
end

#from_orientObject Also known as: expand



146
147
148
149
150
151
152
153
154
155
# File 'lib/other.rb', line 146

def from_orient
 if rid?
   ActiveOrient::Model.autoload_object self
 elsif
   self =~ /^:.*:$/
   self[1..-2].to_sym
 else
   self
 end
end

#quoteObject



189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/other.rb', line 189

def quote
  str = self.dup
  if str[0, 1] == "'" && str[-1, 1] == "'"
    self
  else
    last_pos = 0
    while (pos = str.index("'", last_pos))
      str.insert(pos, "\\") if pos > 0 && str[pos - 1, 1] != "\\"
      last_pos = pos + 1
    end
    "'#{str}'"
  end
end

#ridObject

return a valid rid (format: “nn:mm”) or nil



169
170
171
# File 'lib/other.rb', line 169

def rid
    self["#"].nil? ? self : self[1..-1] if rid? 
end

#rid?Boolean

a rid is either #nn:nn or nn:nn

Returns:

  • (Boolean)


164
165
166
# File 'lib/other.rb', line 164

def rid?
  self =~ /\A[#]{,1}[0-9]{1,}:[0-9]{1,}\z/
end

#to_aObject



185
186
187
# File 'lib/other.rb', line 185

def to_a
  [ self ]
end

#to_classnameObject



173
174
175
176
177
178
179
# File 'lib/other.rb', line 173

def to_classname
  if self[0] == '$'
    self[1..-1]
  else
    self
  end
end

#to_humanObject



207
208
209
# File 'lib/other.rb', line 207

def to_human
  self
end

#to_orObject



181
182
183
# File 'lib/other.rb', line 181

def to_or
 quote
end

#to_orientObject

if the string contains “#xx:yy” omit quotes



159
160
161
# File 'lib/other.rb', line 159

def to_orient
   rid? ? "#"+rid : self   # return the string (not the quoted string. this is to_or)
end

#where(**args) ⇒ Object

end



140
141
142
143
144
# File 'lib/other.rb', line 140

def where **args
  if rid?
    from_orient.where **args
  end
end