Class: KalibroGem::Entities::Reading

Inherits:
Model
  • Object
show all
Defined in:
lib/kalibro_gem/entities/reading.rb

Instance Attribute Summary collapse

Attributes inherited from Model

#kalibro_errors

Class Method Summary collapse

Methods inherited from Model

#==, create, create_array_from_hash, create_objects_array_from_hash, #destroy, #errors=, #initialize, request, #save, #save!, #to_hash, to_object, to_objects_array

Methods included from RequestMethods::ClassMethods

#exists_action, #find_action, #id_params

Methods included from HashConverters

#convert_to_hash, #date_with_milliseconds, #field_to_hash

Methods included from XMLConverters

#get_xml, #xml_instance_class_name

Methods included from RequestMethods

#destroy_action, #destroy_params, #save_action

Constructor Details

This class inherits a constructor from KalibroGem::Entities::Model

Instance Attribute Details

#colorObject

Returns the value of attribute color.



21
22
23
# File 'lib/kalibro_gem/entities/reading.rb', line 21

def color
  @color
end

#gradeObject

Returns the value of attribute grade.



21
22
23
# File 'lib/kalibro_gem/entities/reading.rb', line 21

def grade
  @grade
end

#group_idObject

Returns the value of attribute group_id.



21
22
23
# File 'lib/kalibro_gem/entities/reading.rb', line 21

def group_id
  @group_id
end

#idObject

Returns the value of attribute id.



21
22
23
# File 'lib/kalibro_gem/entities/reading.rb', line 21

def id
  @id
end

#labelObject

Returns the value of attribute label.



21
22
23
# File 'lib/kalibro_gem/entities/reading.rb', line 21

def label
  @label
end

Class Method Details

.allObject



43
44
45
46
47
48
49
50
51
# File 'lib/kalibro_gem/entities/reading.rb', line 43

def self.all
  reading_groups = ReadingGroup.all
  readings = []

  reading_groups.each do |reading_group|
    readings.concat(readings_of(reading_group.id))
  end
  return readings
end

.exists?(id) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
56
57
58
59
# File 'lib/kalibro_gem/entities/reading.rb', line 53

def self.exists?(id)
  begin
    return true unless find(id).nil?
  rescue KalibroGem::Errors::RecordNotFound
    return false
  end
end

.find(id) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/kalibro_gem/entities/reading.rb', line 31

def self.find(id)
  begin
    new request(:get_reading, {:reading_id => id})[:reading]
  rescue Savon::SOAPFault
    raise KalibroGem::Errors::RecordNotFound
  end
end

.readings_of(group_id) ⇒ Object



39
40
41
# File 'lib/kalibro_gem/entities/reading.rb', line 39

def self.readings_of(group_id)
  create_objects_array_from_hash request(:readings_of, {:group_id => group_id})[:reading]
end