Class: AusPost::DRC::ServiceType
- Inherits:
-
Object
- Object
- AusPost::DRC::ServiceType
- Defined in:
- lib/aus_post/drc/service_type.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
-
#description ⇒ Object
Returns the value of attribute description.
-
#short_name ⇒ Object
Returns the value of attribute short_name.
Class Method Summary collapse
- .[](code) ⇒ Object
- .add_mapping(short_name, code, description) ⇒ Object
- .for_select ⇒ Object
- .mapping ⇒ Object
Instance Method Summary collapse
-
#initialize(short_name, code, description) ⇒ ServiceType
constructor
A new instance of ServiceType.
- #matches?(text) ⇒ Boolean
- #to_s ⇒ Object
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
#code ⇒ Object
Returns the value of attribute code.
22 23 24 |
# File 'lib/aus_post/drc/service_type.rb', line 22 def code @code end |
#description ⇒ Object
Returns the value of attribute description.
22 23 24 |
# File 'lib/aus_post/drc/service_type.rb', line 22 def description @description end |
#short_name ⇒ Object
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_select ⇒ Object
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 |
.mapping ⇒ Object
5 6 7 |
# File 'lib/aus_post/drc/service_type.rb', line 5 def self.mapping @mapping ||= [] end |
Instance Method Details
#matches?(text) ⇒ 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_s ⇒ Object
30 31 32 |
# File 'lib/aus_post/drc/service_type.rb', line 30 def to_s @code end |