Class: RubyScriptProvider::URL

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyscriptprovider.rb

Overview

Macro URL.

Constant Summary collapse

EXPAND_PROTOCOL =
"vnd.sun.star.expand:"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ctx, context, url) ⇒ URL

Returns a new instance of URL.



172
173
174
175
176
177
# File 'lib/rubyscriptprovider.rb', line 172

def initialize(ctx, context, url)
  @ctx = ctx
  @context = context
  @url = url
  @url = helper.getRootStorageURI unless url
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



179
180
181
# File 'lib/rubyscriptprovider.rb', line 179

def context
  @context
end

#urlObject (readonly) Also known as: to_s

Returns the value of attribute url.



179
180
181
# File 'lib/rubyscriptprovider.rb', line 179

def url
  @url
end

Instance Method Details

#absolutizeObject



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

def absolutize
  return Uno.absolutize(@url, @url) rescue nil
  return @url
end

#basename(ext = "") ⇒ Object



200
201
202
# File 'lib/rubyscriptprovider.rb', line 200

def basename(ext="")
  return File.basename(@url, ext)
end

#create(url) ⇒ Object



182
183
184
# File 'lib/rubyscriptprovider.rb', line 182

def create(url)
  return RubyScriptProvider::URL.new(@ctx, @context, url)
end

#dirnameObject



204
205
206
# File 'lib/rubyscriptprovider.rb', line 204

def dirname
  return File.dirname(@url)
end

#expand(uri) ⇒ Object



224
225
226
227
228
229
230
231
# File 'lib/rubyscriptprovider.rb', line 224

def expand(uri)
  url = @ctx.getValueByName(
       "/singletons/com.sun.star.util.theMacroExpander").expandMacros(uri)
  url[EXPAND_PROTOCOL] = ""
  url = Uno.absolutize(url, url) rescue nil
  url += "/" if uri.end_with?("/")
  return url
end

#helperObject



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

def helper
  return create_service("com.sun.star.script.provider.ScriptURIHelper", 
    [LANGUAGE, @context])
end

#join(a, b = nil) ⇒ Object



214
215
216
217
218
219
220
221
222
# File 'lib/rubyscriptprovider.rb', line 214

def join(a, b=nil)
  if b
    return a + b if a.end_with?("/")
    return "#{a}/#{b}"
  else
    return @url + a if @url.end_with?("/")
    return "#{@url}/#{a}"
  end
end

#to_uri(function_name = nil) ⇒ Object



208
209
210
211
212
# File 'lib/rubyscriptprovider.rb', line 208

def to_uri(function_name=nil)
  url = @url
  url += "$" + function_name if function_name
  return helper.getScriptURI(url)
end

#to_url(uri) ⇒ Object



233
234
235
236
237
# File 'lib/rubyscriptprovider.rb', line 233

def to_url(uri)
  url = helper.getStorageURI(uri)
  n = url.rindex("$")
  return url[0..n-1], url[n+1..-1]
end

#transient?Boolean

Returns:

  • (Boolean)


196
197
198
# File 'lib/rubyscriptprovider.rb', line 196

def transient?
  return @url.start_with?(DOC_PROTOCOL)
end