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.



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

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.



5
6
7
# File 'lib/rh/klass.rb', line 5

def name
  @name
end

#packagesObject (readonly)

Returns the value of attribute packages.



5
6
7
# File 'lib/rh/klass.rb', line 5

def packages
  @packages
end

#sourceObject (readonly)

Returns the value of attribute source.



5
6
7
# File 'lib/rh/klass.rb', line 5

def source
  @source
end

#versionObject (readonly)

Returns the value of attribute version.



5
6
7
# File 'lib/rh/klass.rb', line 5

def version
  @version
end

Instance Method Details

#escaped_nameObject



15
16
17
# File 'lib/rh/klass.rb', line 15

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

#find_method_by_name(method_name) ⇒ Object



30
31
32
# File 'lib/rh/klass.rb', line 30

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

#find_methods_by_ambiguous_name(ambiguous_method_name) ⇒ Object



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

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



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

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

#urlObject



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

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