Class: SakaiInfo::GradebookItem

Inherits:
SakaiObject show all
Defined in:
lib/sakai-info/gradebook.rb

Instance Attribute Summary collapse

Attributes inherited from SakaiObject

#id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SakaiObject

all_serializations, #dbrow_only_serialization, #dbrow_serialization, descendants, #object_type_serialization, #serialize, #shell_serialization, #to_csv, #to_json, #to_yaml

Constructor Details

#initialize(dbrow) ⇒ GradebookItem

Returns a new instance of GradebookItem.



113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/sakai-info/gradebook.rb', line 113

def initialize(dbrow)
  @dbrow = dbrow

  @id = @dbrow[:id]
  @gradebook_id = @dbrow[:gradebook_id].to_i
  @object_type_id = @dbrow[:object_type_id].to_i
  @version = @dbrow[:version].to_i
  @name = @dbrow[:name]
  @points_possible = @dbrow[:points_possible].to_f
  @due_date = @dbrow[:due_date]
  @weight = @dbrow[:assignment_weighting].to_f
end

Instance Attribute Details

#due_dateObject (readonly)

Returns the value of attribute due_date.



106
107
108
# File 'lib/sakai-info/gradebook.rb', line 106

def due_date
  @due_date
end

#gradebook_idObject (readonly)

Returns the value of attribute gradebook_id.



106
107
108
# File 'lib/sakai-info/gradebook.rb', line 106

def gradebook_id
  @gradebook_id
end

#nameObject (readonly)

Returns the value of attribute name.



106
107
108
# File 'lib/sakai-info/gradebook.rb', line 106

def name
  @name
end

#object_type_idObject (readonly)

Returns the value of attribute object_type_id.



106
107
108
# File 'lib/sakai-info/gradebook.rb', line 106

def object_type_id
  @object_type_id
end

#points_possibleObject (readonly)

Returns the value of attribute points_possible.



106
107
108
# File 'lib/sakai-info/gradebook.rb', line 106

def points_possible
  @points_possible
end

#versionObject (readonly)

Returns the value of attribute version.



106
107
108
# File 'lib/sakai-info/gradebook.rb', line 106

def version
  @version
end

#weightObject (readonly)

Returns the value of attribute weight.



106
107
108
# File 'lib/sakai-info/gradebook.rb', line 106

def weight
  @weight
end

Class Method Details

.clear_cacheObject



108
109
110
# File 'lib/sakai-info/gradebook.rb', line 108

def self.clear_cache
  @@cache = {}
end

.count_by_gradebook_id(gradebook_id) ⇒ Object



145
146
147
# File 'lib/sakai-info/gradebook.rb', line 145

def self.count_by_gradebook_id(gradebook_id)
  GradebookItem.query_by_gradebook_id(gradebook_id).count
end

.find(id) ⇒ Object



126
127
128
129
130
131
132
133
134
135
# File 'lib/sakai-info/gradebook.rb', line 126

def self.find(id)
  if @@cache[id].nil?
    row = DB.connect[:gb_gradable_object_t].where(:id => id).first
    if row.nil?
      raise ObjectNotFoundException.new(GradebookItem, id)
    end
    @@cache[id] = GradebookItem.new(row)
  end
  @@cache[id]
end

.find_by_gradebook_id(gradebook_id) ⇒ Object



149
150
151
# File 'lib/sakai-info/gradebook.rb', line 149

def self.find_by_gradebook_id(gradebook_id)
  GradebookItem.query_by_gradebook_id(gradebook_id).all.collect { |row| GradebookItem.new(row) }
end

.query_by_gradebook_id(gradebook_id) ⇒ Object



141
142
143
# File 'lib/sakai-info/gradebook.rb', line 141

def self.query_by_gradebook_id(gradebook_id)
  DB.connect[:gb_gradable_object_t].where(:gradebook_id => gradebook_id)
end

Instance Method Details

#default_serializationObject



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/sakai-info/gradebook.rb', line 153

def default_serialization
  result = {
    "id" => self.id,
    "name" => self.name,
    "gradebook_id" => self.gradebook_id,
    "object_type_id" => self.object_type_id,
    "version" => self.version,
    "points_possible" => self.points_possible,
    "due_date" => self.due_date,
    "weight" => self.weight
  }
  if self.due_date.nil?
    result.delete("due_date")
  end
  result
end

#gradebookObject



137
138
139
# File 'lib/sakai-info/gradebook.rb', line 137

def gradebook
  @gradebook = Gradebook.find(self.gradebook_id)
end

#summary_serializationObject



170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/sakai-info/gradebook.rb', line 170

def summary_serialization
  result = {
    "id" => self.id,
    "name" => self.name,
    "points_possible" => self.points_possible,
    "due_date" => self.due_date
  }
  if self.due_date.nil?
    result.delete("due_date")
  end
  result
end