Class: Pubid::Ieee::Type
- Inherits:
-
Object
- Object
- Pubid::Ieee::Type
- Defined in:
- lib/pubid/ieee/type.rb
Constant Summary collapse
- TYPE_NAMES =
{ std: { long: "Standard", full: "Std", short: "Std", match: %w[STD Std Standard], alternative: "", }, draft: { full: "Draft Std", short: "Draft Std", match: %w[Draft], alternative: "Draft", }, }.freeze
Instance Attribute Summary collapse
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(type = :std) ⇒ Type
constructor
Create new type.
- #to_s(format = :short) ⇒ Object
Constructor Details
#initialize(type = :std) ⇒ Type
Create new type
23 24 25 26 27 28 29 |
# File 'lib/pubid/ieee/type.rb', line 23 def initialize(type = :std) type = type.to_s.downcase.to_sym unless type.is_a?(Symbol) raise Errors::WrongTypeError, "#{type} type is not available" unless TYPE_NAMES.key?(type) @type = type end |
Instance Attribute Details
#type ⇒ Object
Returns the value of attribute type.
3 4 5 |
# File 'lib/pubid/ieee/type.rb', line 3 def type @type end |
Class Method Details
.parse(type_string) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/pubid/ieee/type.rb', line 31 def self.parse(type_string) TYPE_NAMES.each do |type, values| return new(type) if values[:match].include?(type_string) end raise Errors::ParseTypeError, "Cannot parse '#{type_string}' type" end |
Instance Method Details
#to_s(format = :short) ⇒ Object
38 39 40 |
# File 'lib/pubid/ieee/type.rb', line 38 def to_s(format = :short) TYPE_NAMES[type][format] end |