Class: Cocoadex::GenericRef

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

Overview

A non-class reference document containing functions, constants, callbacks, result codes, and data types

Constant Summary collapse

TEMPLATE_NAME =
:generic_ref

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

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

Methods included from Bri::Templates::Helpers

h3, inline_title, wrap

Constructor Details

This class inherits a constructor from Cocoadex::Entity

Instance Attribute Details

#callbacksObject (readonly)

Returns the value of attribute callbacks.



6
7
8
# File 'lib/cocoadex/models/generic_ref.rb', line 6

def callbacks
  @callbacks
end

#const_groupsObject (readonly)

Returns the value of attribute const_groups.



6
7
8
# File 'lib/cocoadex/models/generic_ref.rb', line 6

def const_groups
  @const_groups
end

#data_typesObject (readonly)

Returns the value of attribute data_types.



6
7
8
# File 'lib/cocoadex/models/generic_ref.rb', line 6

def data_types
  @data_types
end

#functionsObject (readonly)

Returns the value of attribute functions.



6
7
8
# File 'lib/cocoadex/models/generic_ref.rb', line 6

def functions
  @functions
end

#overviewObject (readonly)

Returns the value of attribute overview.



6
7
8
# File 'lib/cocoadex/models/generic_ref.rb', line 6

def overview
  @overview
end

#result_codesObject (readonly)

Returns the value of attribute result_codes.



6
7
8
# File 'lib/cocoadex/models/generic_ref.rb', line 6

def result_codes
  @result_codes
end

#specsObject (readonly)

Returns the value of attribute specs.



6
7
8
# File 'lib/cocoadex/models/generic_ref.rb', line 6

def specs
  @specs
end

Instance Method Details

#constantsObject



24
25
26
# File 'lib/cocoadex/models/generic_ref.rb', line 24

def constants
  @const_groups.map {|g| g.constants}.flatten
end

#parse(doc) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/cocoadex/models/generic_ref.rb', line 11

def parse doc
  @name  = doc.title.sub("Reference","").strip
  @specs = {}

  parse_specbox(doc)
  parse_overview(doc)
  parse_data_types(doc)
  parse_result_codes(doc)
  parse_constants(doc)
  parse_functions(doc)
  parse_callbacks(doc)
end

#parse_callbacks(doc) ⇒ Object



46
47
48
49
# File 'lib/cocoadex/models/generic_ref.rb', line 46

def parse_callbacks doc
  @callbacks = []
  parse_section(doc, @callbacks, "Callbacks", Callback)
end

#parse_constants(doc) ⇒ Object



61
62
63
64
# File 'lib/cocoadex/models/generic_ref.rb', line 61

def parse_constants doc
  @const_groups = []
  parse_section(doc, @const_groups, "Constants",ConstantGroup)
end

#parse_data_types(doc) ⇒ Object



56
57
58
59
# File 'lib/cocoadex/models/generic_ref.rb', line 56

def parse_data_types doc
  @data_types = []
  parse_section(doc, @data_types, "Data Types", DataType)
end

#parse_functions(doc) ⇒ Object



51
52
53
54
# File 'lib/cocoadex/models/generic_ref.rb', line 51

def parse_functions doc
  @functions = []
  parse_section(doc, @functions, "Functions", Function)
end

#parse_overview(doc) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/cocoadex/models/generic_ref.rb', line 28

def parse_overview doc
  if section = section_by_title(doc, "Overview")
    @overview = section.text.sub("Overview","")
  else
    @overview = ""
  end
end

#parse_result_codes(doc) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/cocoadex/models/generic_ref.rb', line 74

def parse_result_codes doc
  @result_codes = []
  if section = section_by_title(doc, "Result Codes")
    table = section.css("table").first
    table.css("tr").each do |row|
      if cells = row.css("td") and cells.size > 0
        value = cells[1].text
        description = cells[2].css("p").map {|p| p.text}.join("\n\n")
        @result_codes << ResultCode.new(@name, cells.first.text, value, description)
      end
    end
  end
end

#parse_section(doc, list, title, klass) ⇒ Object



66
67
68
69
70
71
72
# File 'lib/cocoadex/models/generic_ref.rb', line 66

def parse_section doc, list, title, klass
  if section = section_by_title(doc, title)
    section.css("h3").each do |type_title|
      list << klass.new(@name, type_title)
    end
  end
end

#parse_specbox(doc) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/cocoadex/models/generic_ref.rb', line 36

def parse_specbox doc
  specbox = doc.css(".specbox")
  return if specbox.to_a.empty?
  specbox.first.css("tr").each do |row|
    title = row.css("td").first.css("strong").text
    value = row.css("td").to_a[1].text.strip
    @specs[title] = value
  end
end