Class: Pubid::Iso::Stage
- Inherits:
-
Object
- Object
- Pubid::Iso::Stage
- Defined in:
- lib/pubid/iso/stage.rb
Constant Summary collapse
- STAGES =
{ PWI: "00.00", NP: "10.00", AWI: %w[20.00 10.99], WD: %w[20.20 20.60 20.98 20.99], CD: "30.00", DIS: "40.00", FDIS: "50.00", PRF: "60.00", IS: "60.60" }.freeze
Instance Attribute Summary collapse
-
#abbr ⇒ Object
Returns the value of attribute abbr.
-
#harmonized_code ⇒ Object
Returns the value of attribute harmonized_code.
Class Method Summary collapse
Instance Method Summary collapse
-
#==(other) ⇒ Object
Compares one stage with another.
-
#initialize(abbr: nil, harmonized_code: nil) ⇒ Stage
constructor
A new instance of Stage.
-
#lookup_abbr(lookup_code) ⇒ Object
Lookup for abbreviated code by numeric stage code.
- #lookup_code(lookup_abbr) ⇒ Object
Constructor Details
#initialize(abbr: nil, harmonized_code: nil) ⇒ Stage
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/pubid/iso/stage.rb', line 18 def initialize(abbr: nil, harmonized_code: nil) @abbr = abbr&.to_s if harmonized_code @harmonized_code = if harmonized_code.is_a?(HarmonizedStageCode) harmonized_code else HarmonizedStageCode.new(*harmonized_code.to_s.split(".")) end @abbr ||= lookup_abbr(@harmonized_code.to_s) || lookup_abbr("#{@harmonized_code.stage}.00") end if abbr raise Errors::StageInvalidError, "#{abbr} is not valid stage" unless STAGES.key?(abbr.to_sym) @harmonized_code ||= HarmonizedStageCode.new(*lookup_code(abbr).split(".")) end end |
Instance Attribute Details
#abbr ⇒ Object
Returns the value of attribute abbr.
3 4 5 |
# File 'lib/pubid/iso/stage.rb', line 3 def abbr @abbr end |
#harmonized_code ⇒ Object
Returns the value of attribute harmonized_code.
3 4 5 |
# File 'lib/pubid/iso/stage.rb', line 3 def harmonized_code @harmonized_code end |
Class Method Details
.parse(stage) ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/pubid/iso/stage.rb', line 59 def self.parse(stage) if /\A[\d.]+\z/.match?(stage) Stage.new(harmonized_code: stage) else raise Errors::StageInvalidError unless stage.is_a?(Symbol) || stage.is_a?(String) Stage.new(abbr: stage) end end |
Instance Method Details
#==(other) ⇒ Object
Compares one stage with another
70 71 72 |
# File 'lib/pubid/iso/stage.rb', line 70 def ==(other) other&.harmonized_code == harmonized_code end |
#lookup_abbr(lookup_code) ⇒ Object
Lookup for abbreviated code by numeric stage code
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/pubid/iso/stage.rb', line 39 def lookup_abbr(lookup_code) STAGES.each do |abbr, codes| case codes when Array codes.each do |code| return abbr if code == lookup_code end when lookup_code return abbr end end nil end |
#lookup_code(lookup_abbr) ⇒ Object
54 55 56 57 |
# File 'lib/pubid/iso/stage.rb', line 54 def lookup_code(lookup_abbr) code = STAGES[lookup_abbr.to_sym] code.is_a?(Array) ? code.first : code end |