Class: String

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

Instance Method Summary collapse

Instance Method Details

#capitalize_first_letterObject


134
135
136
# File 'lib/other.rb', line 134

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

#coerce(a) ⇒ Object

nodoc#


209
210
211
# File 'lib/other.rb', line 209

def coerce a  #nodoc#
 nil	
end

#from_orientObject Also known as: expand


152
153
154
155
156
157
158
159
160
161
# File 'lib/other.rb', line 152

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

#quoteObject


195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/other.rb', line 195

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


175
176
177
# File 'lib/other.rb', line 175

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

#rid?Boolean

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

Returns:

  • (Boolean)

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

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

#to_aObject


191
192
193
# File 'lib/other.rb', line 191

def to_a
  [ self ]
end

#to_classnameObject


179
180
181
182
183
184
185
# File 'lib/other.rb', line 179

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

#to_humanObject


213
214
215
# File 'lib/other.rb', line 213

def to_human
	self
end

#to_orObject


187
188
189
# File 'lib/other.rb', line 187

def to_or
 quote
end

#to_orientObject

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


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

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

#where(**args) ⇒ Object

as_json has unexpected side-effects, needs further consideration

def as_json o=nil
  if rid?
    rid
  else
   super o
  end
end

146
147
148
149
150
# File 'lib/other.rb', line 146

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