Class: DocStat::Container

Inherits:
Object
  • Object
show all
Defined in:
lib/docstat/container.rb

Constant Summary collapse

QUERY =
"select ZCONTAINERNAME,ZTOKENNAME,ZTYPENAME,ZTOKENMETAINFORMATION.ZABSTRACT,ZDECLARATION from ZTOKEN \
left join ZCONTAINER on ZTOKEN.ZCONTAINER = ZCONTAINER.Z_PK \
left join ZTOKENTYPE on ZTOKEN.ZTOKENTYPE = ZTOKENTYPE.Z_PK \
left join ZTOKENMETAINFORMATION on ZTOKEN.Z_PK = ZTOKENMETAINFORMATION.ZTOKEN \
order by ZCONTAINERNAME"
QUERY_WITH_RETURN_VALUES =
"select ZCONTAINERNAME,ZTOKENNAME,ZTYPENAME,ZTOKENMETAINFORMATION.ZABSTRACT,ZDECLARATION,ZRETURNVALUE.ZABSTRACT from ZTOKEN \
left join ZCONTAINER on ZTOKEN.ZCONTAINER = ZCONTAINER.Z_PK \
left join ZTOKENTYPE on ZTOKEN.ZTOKENTYPE = ZTOKENTYPE.Z_PK \
left join ZTOKENMETAINFORMATION on ZTOKEN.Z_PK = ZTOKENMETAINFORMATION.ZTOKEN \
left join ZRETURNVALUE on ZTOKENMETAINFORMATION.ZRETURNVALUE = ZRETURNVALUE.Z_PK \
order by ZCONTAINERNAME"
RETURNVALUES_QUERY =
"SELECT * FROM sqlite_master WHERE type='table'"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, tokens) ⇒ Container

Returns a new instance of Container.



35
36
37
# File 'lib/docstat/container.rb', line 35

def initialize name, tokens
  @name, @tokens = name, tokens.map {|t| Token.new(t)}
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/docstat/container.rb', line 7

def name
  @name
end

#tokensObject (readonly)

Returns the value of attribute tokens.



7
8
9
# File 'lib/docstat/container.rb', line 7

def tokens
  @tokens
end

Class Method Details

.from_sqlite(path) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/docstat/container.rb', line 24

def self.from_sqlite path
  db = SQLite3::Database.new(path)
  rows = has_return_values?(db) ? db.execute(QUERY_WITH_RETURN_VALUES) : db.execute(QUERY)
  container_groups = rows.group_by {|r| r.first }
  groups = container_groups.map do |name, tokens|
    self.new(name, tokens)
  end
  db.close
  groups
end

.has_return_values?(database) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/docstat/container.rb', line 39

def self.has_return_values? database
  database.execute(RETURNVALUES_QUERY).detect {|r| r[1] == 'ZRETURNVALUE'} != nil
end

Instance Method Details

#descriptionObject



63
64
65
66
# File 'lib/docstat/container.rb', line 63

def description
  token_description = tokens.map {|t| t.description}.join("\n")
  "#{name}:\n#{token_description}"
end

#method_documentation_ratioObject



55
56
57
# File 'lib/docstat/container.rb', line 55

def method_documentation_ratio
  documentation_ratio(tokens.select(:method?))
end

#property_documentation_ratioObject



59
60
61
# File 'lib/docstat/container.rb', line 59

def property_documentation_ratio
  documentation_ratio(tokens.select(:property?))
end

#ratioObject



51
52
53
# File 'lib/docstat/container.rb', line 51

def ratio
  documentation_ratio(tokens)
end

#to_hashObject



43
44
45
46
47
48
49
# File 'lib/docstat/container.rb', line 43

def to_hash
  {
    "name"   => name,
    "tokens" => tokens.map(&:to_hash),
    "ratio"  => ratio
  }
end