Class: Rh::Method

Inherits:
Object
  • Object
show all
Includes:
HasUrl
Defined in:
lib/rh/method.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HasUrl

#core_url, #stdlib_url

Constructor Details

#initialize(options = {}) ⇒ Method

Returns a new instance of Method.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rh/method.rb', line 10

def initialize(options={})
  @klass = options['klass']
  @source = options['source']
  @package = options['package']
  @version = options['version']
  @name = options['name']
  match = name.match(/(#|::)(.+)/)
  raise "Invalid method name: #{name} in #{klass.name}" unless match
  @type = match[1] == '#' ? :instance : :class
  @raw_name = match[2]
end

Instance Attribute Details

#klassObject (readonly)

Returns the value of attribute klass.



8
9
10
# File 'lib/rh/method.rb', line 8

def klass
  @klass
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/rh/method.rb', line 8

def name
  @name
end

#packageObject (readonly)

Returns the value of attribute package.



8
9
10
# File 'lib/rh/method.rb', line 8

def package
  @package
end

#raw_nameObject (readonly)

Returns the value of attribute raw_name.



8
9
10
# File 'lib/rh/method.rb', line 8

def raw_name
  @raw_name
end

#sourceObject (readonly)

Returns the value of attribute source.



8
9
10
# File 'lib/rh/method.rb', line 8

def source
  @source
end

#typeObject (readonly)

Returns the value of attribute type.



8
9
10
# File 'lib/rh/method.rb', line 8

def type
  @type
end

#versionObject (readonly)

Returns the value of attribute version.



8
9
10
# File 'lib/rh/method.rb', line 8

def version
  @version
end

Instance Method Details

#escaped_nameObject



22
23
24
# File 'lib/rh/method.rb', line 22

def escaped_name
  CGI.escape(raw_name).gsub('%', '-')
end

#urlObject



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rh/method.rb', line 26

def url
  type_string = type == :class ? 'c' : 'i'
  case source
  when 'core'
    "#{core_url}/#{klass.escaped_name}.html#method-#{type_string}-#{escaped_name}"
  when 'stdlib'
    "#{stdlib_url}/#{package}/rdoc/#{klass.escaped_name}.html#method-#{type_string}-#{escaped_name}"
  else
    raise 'Unable to generate URL'
  end
end