Class: AusPost::DRC::ServiceType

Inherits:
Object
  • Object
show all
Defined in:
lib/aus_post/drc/service_type.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(short_name, code, description) ⇒ ServiceType

Returns a new instance of ServiceType.



24
25
26
27
28
# File 'lib/aus_post/drc/service_type.rb', line 24

def initialize(short_name, code, description)
  @short_name  = short_name.to_s
  @code        = code.to_s
  @description = description.to_s
end

Instance Attribute Details

#codeObject

Returns the value of attribute code.



22
23
24
# File 'lib/aus_post/drc/service_type.rb', line 22

def code
  @code
end

#descriptionObject

Returns the value of attribute description.



22
23
24
# File 'lib/aus_post/drc/service_type.rb', line 22

def description
  @description
end

#short_nameObject

Returns the value of attribute short_name.



22
23
24
# File 'lib/aus_post/drc/service_type.rb', line 22

def short_name
  @short_name
end

Class Method Details

.[](code) ⇒ Object



13
14
15
16
# File 'lib/aus_post/drc/service_type.rb', line 13

def self.[](code)
  item = mapping.detect { |st| st.matches?(code) }
  item && item.code
end

.add_mapping(short_name, code, description) ⇒ Object



9
10
11
# File 'lib/aus_post/drc/service_type.rb', line 9

def self.add_mapping(short_name, code, description)
  mapping << ServiceType.new(short_name, code, description)
end

.for_selectObject



18
19
20
# File 'lib/aus_post/drc/service_type.rb', line 18

def self.for_select
  mapping.map { |st| [st.description, st.short_name.to_s] }
end

.mappingObject



5
6
7
# File 'lib/aus_post/drc/service_type.rb', line 5

def self.mapping
  @mapping ||= []
end

Instance Method Details

#matches?(text) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
37
# File 'lib/aus_post/drc/service_type.rb', line 34

def matches?(text)
  text = text.to_s.strip
  !text.empty? && [short_name, code, description].any? { |v| v == text }
end

#to_sObject



30
31
32
# File 'lib/aus_post/drc/service_type.rb', line 30

def to_s
  @code
end