Class: Rh::Klass

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HasUrl

#core_url, #stdlib_url

Constructor Details

#initialize(options = {}) ⇒ Klass

Returns a new instance of Klass.



9
10
11
12
13
14
15
# File 'lib/rh/klass.rb', line 9

def initialize(options={})
  @name = options['name']
  @source = options['source']
  @version = options['version']
  @packages = options['packages']
  @options = options
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/rh/klass.rb', line 7

def name
  @name
end

#packagesObject (readonly)

Returns the value of attribute packages.



7
8
9
# File 'lib/rh/klass.rb', line 7

def packages
  @packages
end

#sourceObject (readonly)

Returns the value of attribute source.



7
8
9
# File 'lib/rh/klass.rb', line 7

def source
  @source
end

#versionObject (readonly)

Returns the value of attribute version.



7
8
9
# File 'lib/rh/klass.rb', line 7

def version
  @version
end

Instance Method Details

#escaped_nameObject



17
18
19
# File 'lib/rh/klass.rb', line 17

def escaped_name
  name.gsub('::', '/')
end

#find_method_by_name(method_name) ⇒ Object



32
33
34
# File 'lib/rh/klass.rb', line 32

def find_method_by_name(method_name)
  methods.find { |method| method.name == method_name }
end

#find_methods_by_ambiguous_name(ambiguous_method_name) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/rh/klass.rb', line 36

def find_methods_by_ambiguous_name(ambiguous_method_name)
  if ambiguous_method_name.start_with?('#') || ambiguous_method_name.start_with?('::')
    methods.select { |method| method.name == ambiguous_method_name }
  else
    methods.select { |method| method.raw_name == ambiguous_method_name }
  end
end

#methodsObject



44
45
46
47
48
49
50
# File 'lib/rh/klass.rb', line 44

def methods
  @methods ||= begin
    @options['methods'].map do |method|
      Rh::Method.new(method.merge('klass' => self, 'version' => version))
    end
  end
end

#urlObject



21
22
23
24
25
26
27
28
29
30
# File 'lib/rh/klass.rb', line 21

def url
  case source
  when 'stdlib'
    "#{stdlib_url}/#{packages.first}/rdoc/#{escaped_name}.html"
  when 'core'
    "#{core_url}/#{escaped_name}.html"
  else
    raise 'Unable to generate URL'
  end
end