Class: ServiceSummary

Inherits:
Object
  • Object
show all
Defined in:
lib/tbr/service_summary.rb

Constant Summary collapse

DS_CODE =

OBS record type DS - page 30

0
DS_SERVICE =
6
DS_TYPE =
8
DS_CALL_TYPE =
10
DS_SERVICE_TYPE =
11
DS_UNITS =
12
DS_CALL_COUNT =
13
DS_START_DATE =
15
DS_COST =
33

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record, call_type) ⇒ ServiceSummary

Returns a new instance of ServiceSummary.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/tbr/service_summary.rb', line 20

def initialize(record,call_type)
	fields = record.split(',')
	if fields[DS_CODE] == 'DS' && fields[DS_TYPE] == 'D' then  # Service Summary and Detail record
		@service_number = fields[DS_SERVICE]
		@call_type = call_type.desc(fields[DS_CALL_TYPE])
		@service_type = fields[DS_SERVICE_TYPE]
		@units = fields[DS_UNITS]
		@call_count = fields[DS_CALL_COUNT].to_i
		@start_date = Time.parse(fields[DS_START_DATE]).strftime('%d/%m/%Y')
		fields[16] == '' ? @end_date = '' : @end_date = Time.parse(fields[16]).strftime('%d/%m/%Y')
		@cost = fields[DS_COST].to_f
	else
		raise ArgumentError, "Invalid record type - " + fields[DS_CODE], caller
	end
end

Instance Attribute Details

#call_countObject (readonly)

Returns the value of attribute call_count.



17
18
19
# File 'lib/tbr/service_summary.rb', line 17

def call_count
  @call_count
end

#call_typeObject (readonly)

Returns the value of attribute call_type.



17
18
19
# File 'lib/tbr/service_summary.rb', line 17

def call_type
  @call_type
end

#costObject (readonly)

Returns the value of attribute cost.



17
18
19
# File 'lib/tbr/service_summary.rb', line 17

def cost
  @cost
end

#end_dateObject (readonly)

Returns the value of attribute end_date.



17
18
19
# File 'lib/tbr/service_summary.rb', line 17

def end_date
  @end_date
end

#service_numberObject (readonly)

Returns the value of attribute service_number.



17
18
19
# File 'lib/tbr/service_summary.rb', line 17

def service_number
  @service_number
end

#service_typeObject (readonly)

Returns the value of attribute service_type.



17
18
19
# File 'lib/tbr/service_summary.rb', line 17

def service_type
  @service_type
end

#start_dateObject (readonly)

Returns the value of attribute start_date.



17
18
19
# File 'lib/tbr/service_summary.rb', line 17

def start_date
  @start_date
end

#unitsObject (readonly)

Returns the value of attribute units.



17
18
19
# File 'lib/tbr/service_summary.rb', line 17

def units
  @units
end

Instance Method Details

#to_aObject



36
37
38
39
40
# File 'lib/tbr/service_summary.rb', line 36

def to_a
	call_count = @call_count == 0 ? call_count = "" : call_count = sprintf("%d",@call_count)
	cost = sprintf("%0.2f",@cost)
	[@call_type, @service_type, call_count, @units, cost]
end