Class: Cocoadex::Class

Inherits:
Entity show all
Defined in:
lib/cocoadex/models/class.rb

Overview

A model of a Cocoa API class or protocol

Constant Summary collapse

TEMPLATE_NAME =
:class

Instance Attribute Summary collapse

Attributes inherited from Entity

#path

Attributes inherited from Element

#name

Instance Method Summary collapse

Methods inherited from Entity

#clean, #initialize, #section_by_title, #strip

Methods inherited from Element

#<=>, #parse_parameters, #print, #to_s

Methods included from Bri::Templates::Helpers

h3, inline_title, wrap

Constructor Details

This class inherits a constructor from Cocoadex::Entity

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



9
10
11
# File 'lib/cocoadex/models/class.rb', line 9

def description
  @description
end

#overviewObject (readonly)

Returns the value of attribute overview.



9
10
11
# File 'lib/cocoadex/models/class.rb', line 9

def overview
  @overview
end

Instance Method Details

#class_methodsObject



23
24
25
# File 'lib/cocoadex/models/class.rb', line 23

def class_methods
  methods.select{|m| m.scope == :class }
end

#instance_methodsObject



27
28
29
# File 'lib/cocoadex/models/class.rb', line 27

def instance_methods
  methods.select{|m| m.scope == :instance }
end

#methodsObject



19
20
21
# File 'lib/cocoadex/models/class.rb', line 19

def methods
  @methods ||= ::Set.new
end

#originObject



39
40
41
# File 'lib/cocoadex/models/class.rb', line 39

def origin
  parents.join(' > ')
end

#parentsObject



31
32
33
# File 'lib/cocoadex/models/class.rb', line 31

def parents
  @parents ||= []
end

#parse(doc) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/cocoadex/models/class.rb', line 43

def parse doc
  @name = doc.css('body a').first['title']
  @description = doc.css('meta#description').first['content']
  # @overview = doc.css(".zClassDescription p.abstract").first.text
  @overview = doc.css(".zClassDescription").first.children.map {|n| n.text.sub("Overview","") }
  @parents = doc.css("div.zSharedSpecBoxHeadList").first.css('a').map {|node| node.text}

  parse_properties(doc)
  # parse_tasks(doc)
  parse_methods(doc)
end

#parse_methods(doc) ⇒ Object



55
56
57
58
59
60
61
62
# File 'lib/cocoadex/models/class.rb', line 55

def parse_methods doc
  [:class, :instance].each do |selector|
    nodes = doc.css("div.#{selector}Method")
    unless nodes.empty?
      methods.merge(nodes.map {|n| Method.new(self, selector, n)})
    end
  end
end

#parse_properties(doc) ⇒ Object



64
65
66
67
68
# File 'lib/cocoadex/models/class.rb', line 64

def parse_properties doc
  @properties = doc.css("div.propertyObjC").map do |prop|
    Property.new(self, prop)
  end
end

#parse_tasks(doc) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/cocoadex/models/class.rb', line 70

def parse_tasks doc
  @tasks = {}
  doc.css('ul.tooltip').each do |list|
    key = list.previous.text
    @tasks[key] = []
    list.css('li span.tooltip').each do |prop|
      @tasks[key] << {
        :name => strip(prop.css('a').first.text),
        :abstract => prop.css('.tooltipicon').first['data-abstract']
      }
    end
  end
  @tasks
end

#propertiesObject



11
12
13
# File 'lib/cocoadex/models/class.rb', line 11

def properties
  @properties ||=[]
end

#tasksObject



15
16
17
# File 'lib/cocoadex/models/class.rb', line 15

def tasks
  @tasks ||= []
end

#typeObject



35
36
37
# File 'lib/cocoadex/models/class.rb', line 35

def type
  "Class"
end