Class: QDA::CodeReview

Inherits:
Object
  • Object
show all
Defined in:
lib/weft/codereview.rb

Overview

CodeReview is a class that is used for cross-tabulation of coding. It makes it possible to get statistics for the number of characters, passages and documents that are coded by both the row column and the

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCodeReview

A new CodeReview is empty when initialised



10
11
12
13
# File 'lib/weft/codereview.rb', line 10

def initialize()
  @cols, @rows, @contents = [], [], []
  @count_method = :num_of_docs
end

Instance Attribute Details

#colsObject (readonly)

Returns the value of attribute cols.



7
8
9
# File 'lib/weft/codereview.rb', line 7

def cols
  @cols
end

#contentsObject (readonly)

Returns the value of attribute contents.



7
8
9
# File 'lib/weft/codereview.rb', line 7

def contents
  @contents
end

#count_methodObject

Returns the value of attribute count_method.



6
7
8
# File 'lib/weft/codereview.rb', line 6

def count_method
  @count_method
end

#dbidObject

Returns the value of attribute dbid.



6
7
8
# File 'lib/weft/codereview.rb', line 6

def dbid
  @dbid
end

#rowsObject (readonly)

Returns the value of attribute rows.



7
8
9
# File 'lib/weft/codereview.rb', line 7

def rows
  @rows
end

Instance Method Details

#add_col(category) ⇒ Object

add the Category category as the last column



31
32
33
34
35
36
37
38
39
# File 'lib/weft/codereview.rb', line 31

def add_col(category)
  return nil unless category
  return nil if @cols.include?(category)
  @cols.push(category)
  
  @rows.each_with_index do | row_cat, i |
    @contents[i][last_col] = row_cat.codes.dup.join(category.codes)
  end
end

#add_row(category) ⇒ Object

appends the category category as the last row. Returns the appended category if it was successfully added, or nil f not - for example, if



80
81
82
83
84
85
86
87
88
# File 'lib/weft/codereview.rb', line 80

def add_row(category)
  return nil unless category
  return nil if @rows.include?(category)
  @rows.push(category)
  @contents[last_row] = []      
  @cols.each_with_index do | col_cat, j |
    @contents[last_row][j] = col_cat.codes.dup.join(category.codes)
  end
end

#each_cellObject



111
112
113
114
115
# File 'lib/weft/codereview.rb', line 111

def each_cell()
  0.upto(last_row) do | i |
    0.upto(last_col) { | j | yield i, j, @contents[i][j] }
  end
end

#each_cell_value(meth = @count_method) ⇒ Object

loops over the contents of this code review, yielding each cell’s location and value (calculated by meth, defaulting to the code review’s current count_method. Values are yielded as follows

code_review.each_cell { | row_num, col_num, cell_value |


123
124
125
# File 'lib/weft/codereview.rb', line 123

def each_cell_value(meth = @count_method)
  each_cell { | i, j, cell | yield i, j, cell.send(meth) }
end

#each_colObject

takes a block, yielding each column Category and its index in turn



26
27
28
# File 'lib/weft/codereview.rb', line 26

def each_col()
  @cols.each_with_index { | col, i | yield col, i }
end

#each_rowObject



74
75
76
# File 'lib/weft/codereview.rb', line 74

def each_row()
  @rows.each_with_index { | r, i | yield r, i }
end

#last_colObject

returns the index of the last column



21
22
23
# File 'lib/weft/codereview.rb', line 21

def last_col()
  @cols.length - 1
end

#last_rowObject

returns the index of the last row in the CodeReview



70
71
72
# File 'lib/weft/codereview.rb', line 70

def last_row()
  @rows.length - 1
end

#max(meth = @count_method) ⇒ Object

returns the maximum value among the codereview contents using the metric method - which should be a method called upon QDA::CodingTable



129
130
131
# File 'lib/weft/codereview.rb', line 129

def max(meth = @count_method)
  @contents.flatten.collect { | x | x.send(meth) }.max
end

#min(meth = @count_method) ⇒ Object

returns the minimum value among the codereview contents using the metric method - which should be a method called upon QDA::CodingTable



135
136
137
# File 'lib/weft/codereview.rb', line 135

def min(meth = @count_method)
  @contents.flatten.collect { | x | x.send(meth) }.min
end

#number_colsObject

returns the total number of columns



16
17
18
# File 'lib/weft/codereview.rb', line 16

def number_cols()
  @cols.length
end

#number_rowsObject

returns the total number of rows in the CodeReview



65
66
67
# File 'lib/weft/codereview.rb', line 65

def number_rows()
  @rows.length
end

#output_rows(with_header = true) ⇒ Object

returns the current content as a series of rows; if with_array is true, a header row of column names will be the first row, and each subsequent row will have the name of the row as the first entry.



142
143
144
145
146
147
148
149
150
151
# File 'lib/weft/codereview.rb', line 142

def output_rows(with_header = true)
  out_rows = []
  out_rows << [ '', *cols.map { | cat | cat.name } ] if with_header
  each_row do | row, i |
    this_row = contents[i].map { | isect | isect.send(count_method) }
    this_row.unshift(row.name) if with_header
    out_rows.push(this_row)
  end
  out_rows
end

#remove_col(category) ⇒ Object

Removes the Category category as a column from the CodeReview. Returns the index of the removed category, if found, or nil, if not.



56
57
58
59
60
61
62
# File 'lib/weft/codereview.rb', line 56

def remove_col(category)
  return nil unless category
  return nil unless idx = @cols.index(category)
  @cols.delete_at(idx)
  @contents.each { | row | row.delete_at(idx) }
  return idx
end

#remove_row(category) ⇒ Object

Removes the Category category from the rows of this CodeReview. Returns the index of the corresponding category, if found, or nil, if not.



103
104
105
106
107
108
109
# File 'lib/weft/codereview.rb', line 103

def remove_row(category)
  return nil unless category
  return nil unless idx = @rows.index(category)
  @rows.delete_at(idx)
  @contents.delete_at(idx)
  return idx
end

#to_query(app, x, y) ⇒ Object



153
154
155
156
157
158
# File 'lib/weft/codereview.rb', line 153

def to_query(app, x, y)
  return nil unless rows[x] and cols[y]
  query = Query.new( Query::CodedByFunction.new(app, rows[x]) )
  query.add_expression( 'AND', Query::CodedByFunction.new(app, cols[y]) )
  query
end

#update_col(category) ⇒ Object

Updates the column with the changed Category category. Useful in a persistent environment where user actions may have altered the coding.



43
44
45
46
47
48
49
50
51
52
# File 'lib/weft/codereview.rb', line 43

def update_col(category)
  return nil unless category
  return nil unless idx = @rows.index(category)

  @rows[idx] = category
  @cols.each_with_index do | col_cat, j |
    @contents[idx][j] = col_cat.codes.dup.join(category.codes)
  end
  return idx
end

#update_row(category) ⇒ Object



91
92
93
94
95
96
97
98
99
# File 'lib/weft/codereview.rb', line 91

def update_row(category)
  return nil unless category
  return nil unless idx = @rows.index(category)
  @rows[idx] = category
  @cols.each_with_index do | col_cat, j |
    @contents[idx][j] = col_cat.codes.dup.join(category.codes)
  end
  return idx
end