Class: Gloo::Objs::Uri

Inherits:
Core::Obj show all
Defined in:
lib/gloo/objs/web/uri.rb

Constant Summary collapse

KEYWORD =
'uri'.freeze
KEYWORD_SHORT =
'url'.freeze

Constants inherited from Core::Baseo

Core::Baseo::NOT_IMPLEMENTED_ERR

Instance Attribute Summary

Attributes inherited from Core::Obj

#children, #parent, #value

Attributes inherited from Core::Baseo

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Core::Obj

#add_child, #add_children_on_create?, #add_default_children, can_create?, #can_receive_message?, #child_count, #child_index, #contains_child?, #delete_children, #dispatch, #display_value, #find_add_child, #find_child, #find_child_resolve_alias, #find_child_value, help, inherited, #initialize, #is_alias?, #is_function?, #msg_blank?, #msg_contains?, #msg_reload, #msg_unload, #pn, #remove_child, #render, #root?, #send_message, #set_parent, #type_display, #value_display, #value_is_array?, #value_is_blank?, #value_string?

Methods inherited from Core::Baseo

#initialize, #type_display

Constructor Details

This class inherits a constructor from Gloo::Core::Obj

Class Method Details

.messagesObject

Get a list of message names that this object receives.



53
54
55
56
57
58
# File 'lib/gloo/objs/web/uri.rb', line 53

def self.messages
  basic = %w[open]
  gets = %w[get_scheme get_host get_path]
  more = %w[get_query get_fragment get_cert_expires]
  return super + basic + gets + more
end

.open_url(url) ⇒ Object

Open the given URL with platform command.



152
153
154
155
156
157
158
159
160
161
# File 'lib/gloo/objs/web/uri.rb', line 152

def self.open_url url
  cmd = Gloo::Core::GlooSystem.open_for_platform
  cmd_with_param = "#{cmd} \"#{url}\""

  if OS.mac?
    `#{cmd_with_param}`
  else
    exec cmd_with_param
  end
end

.short_typenameObject

The short name of the object type.



27
28
29
# File 'lib/gloo/objs/web/uri.rb', line 27

def self.short_typename
  return KEYWORD_SHORT
end

.typenameObject

The name of the object type.



20
21
22
# File 'lib/gloo/objs/web/uri.rb', line 20

def self.typename
  return KEYWORD
end

Instance Method Details

#msg_get_cert_expiresObject

Get the expiration date for the certificate.



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/gloo/objs/web/uri.rb', line 63

def msg_get_cert_expires
  return unless value
  o = value
  uri = URI( value )
  response = Net::HTTP.start( uri.host, uri.port, :use_ssl => true )
  cert = response.peer_cert
  o = cert.not_after

  @engine.heap.it.set_to o
  return o
end

#msg_get_fragmentObject

Get the URI fragment that comes after the ‘#’ in the URL. Might be used to scroll down in the page.



79
80
81
82
83
84
85
# File 'lib/gloo/objs/web/uri.rb', line 79

def msg_get_fragment
  return unless value

  o = URI( value ).fragment
  @engine.heap.it.set_to o
  return o
end

#msg_get_hostObject

Get the URI host. Example: google.com



115
116
117
118
119
120
121
# File 'lib/gloo/objs/web/uri.rb', line 115

def msg_get_host
  return unless value

  o = URI( value ).host
  @engine.heap.it.set_to o
  return o
end

#msg_get_pathObject

Get the URI path. Example: /posts



103
104
105
106
107
108
109
# File 'lib/gloo/objs/web/uri.rb', line 103

def msg_get_path
  return unless value

  o = URI( value ).path
  @engine.heap.it.set_to o
  return o
end

#msg_get_queryObject

Get the URI query parameters. Example: id=121



91
92
93
94
95
96
97
# File 'lib/gloo/objs/web/uri.rb', line 91

def msg_get_query
  return unless value

  o = URI( value ).query
  @engine.heap.it.set_to o
  return o
end

#msg_get_schemeObject

Get the URI Scheme. Example: http



127
128
129
130
131
132
133
# File 'lib/gloo/objs/web/uri.rb', line 127

def msg_get_scheme
  return unless value

  o = URI( value ).scheme
  @engine.heap.it.set_to o
  return o
end

#msg_openObject

Open the URI in the default browser.



138
139
140
141
142
# File 'lib/gloo/objs/web/uri.rb', line 138

def msg_open
  return unless value

  Gloo::Objs::Uri.open_url value
end

#multiline_value?Boolean

Does this object support multi-line values? Initially only true for scripts.

Returns:



42
43
44
# File 'lib/gloo/objs/web/uri.rb', line 42

def multiline_value?
  return false
end

#set_value(new_value) ⇒ Object

Set the value with any necessary type conversions.



34
35
36
# File 'lib/gloo/objs/web/uri.rb', line 34

def set_value( new_value )
  self.value = new_value.to_s
end