Class: Pubid::Jis::Identifiers::Base
- Inherits:
-
Identifier
- Object
- Lutaml::Model::Serializable
- Identifier
- Pubid::Jis::Identifiers::Base
- Defined in:
- lib/pubid/jis/identifiers/base.rb
Overview
Base class for all JIS identifiers Provides common attributes and behavior
Direct Known Subclasses
Instance Method Summary collapse
-
#==(other) ⇒ Object
Comparison with all_parts logic When either identifier has all_parts=true, compare only series and number.
- #all_parts? ⇒ Boolean
-
#code ⇒ String
Generate URN for this identifier.
-
#initialize(code: nil, series: nil, number: nil, parts: nil, year: nil, language: nil, all_parts: false) ⇒ Base
constructor
A new instance of Base.
-
#publisher ⇒ Object
Publisher is always JIS.
-
#to_s ⇒ Object
Basic string representation (override in subclasses).
Methods inherited from Identifier
#base_identifier, #eql?, #exclude, #hash, #mr_number, #mr_number_with_part, #mr_part, #mr_publisher, #mr_type, #mr_year, #new_edition_of?, polymorphic_name, #render, #resolve_urn_generator, #root, #to_mr_string, #to_supplement_s, #to_urn, #urn_supplement_type, #urn_type_code
Constructor Details
#initialize(code: nil, series: nil, number: nil, parts: nil, year: nil, language: nil, all_parts: false) ⇒ Base
Returns a new instance of Base.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/pubid/jis/identifiers/base.rb', line 18 def initialize(code: nil, series: nil, number: nil, parts: nil, year: nil, language: nil, all_parts: false) if code @code = code elsif series && number @code = Components::Code.new( series: series, number: number, parts: parts || [], ) end @year = year @language = language @all_parts = all_parts end |
Instance Method Details
#==(other) ⇒ Object
Comparison with all_parts logic When either identifier has all_parts=true, compare only series and number
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/pubid/jis/identifiers/base.rb', line 45 def ==(other) return false unless other.is_a?(Base) if all_parts? || other.all_parts? # Compare only series and number, ignore year, parts, all_parts return code.series == other.code.series && code.number == other.code.number end # Normal full comparison code == other.code && year == other.year && language == other.language && all_parts == other.all_parts end |
#all_parts? ⇒ Boolean
39 40 41 |
# File 'lib/pubid/jis/identifiers/base.rb', line 39 def all_parts? all_parts == true end |
#code ⇒ String
Generate URN for this identifier
13 |
# File 'lib/pubid/jis/identifiers/base.rb', line 13 attribute :code, Pubid::Jis::Components::Code |
#publisher ⇒ Object
Publisher is always JIS
35 36 37 |
# File 'lib/pubid/jis/identifiers/base.rb', line 35 def publisher "JIS" end |
#to_s ⇒ Object
Basic string representation (override in subclasses)
62 63 64 65 66 67 68 |
# File 'lib/pubid/jis/identifiers/base.rb', line 62 def to_s parts = [publisher, code.to_s] parts << ":#{year}" if year parts << "(#{language})" if language parts << "(規格群)" if all_parts? parts.join(" ") end |