Class: Pubid::Iso::RenderingStyle
- Inherits:
-
Object
- Object
- Pubid::Iso::RenderingStyle
- Defined in:
- lib/pubid/iso/rendering_style.rb
Overview
Base class for rendering styles using Strategy pattern Each identifier stores its own rendering_style which knows how to render it
Direct Known Subclasses
RefDated, RefDatedLong, RefNumLong, RefNumShort, RefUndated, RefUndatedLong
Instance Attribute Summary collapse
-
#stage_format_long ⇒ Object
readonly
Returns the value of attribute stage_format_long.
-
#with_date ⇒ Object
readonly
Returns the value of attribute with_date.
-
#with_language_code ⇒ Object
readonly
Returns the value of attribute with_language_code.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(with_language_code:, stage_format_long:, with_date:) ⇒ RenderingStyle
constructor
A new instance of RenderingStyle.
-
#render(identifier, with_edition: false) ⇒ Object
Render the identifier according to this style Subclasses should override if needed.
- #single_char_language? ⇒ Boolean
Constructor Details
#initialize(with_language_code:, stage_format_long:, with_date:) ⇒ RenderingStyle
Returns a new instance of RenderingStyle.
10 11 12 13 14 |
# File 'lib/pubid/iso/rendering_style.rb', line 10 def initialize(with_language_code:, stage_format_long:, with_date:) @with_language_code = with_language_code @stage_format_long = stage_format_long @with_date = with_date end |
Instance Attribute Details
#stage_format_long ⇒ Object (readonly)
Returns the value of attribute stage_format_long.
8 9 10 |
# File 'lib/pubid/iso/rendering_style.rb', line 8 def stage_format_long @stage_format_long end |
#with_date ⇒ Object (readonly)
Returns the value of attribute with_date.
8 9 10 |
# File 'lib/pubid/iso/rendering_style.rb', line 8 def with_date @with_date end |
#with_language_code ⇒ Object (readonly)
Returns the value of attribute with_language_code.
8 9 10 |
# File 'lib/pubid/iso/rendering_style.rb', line 8 def with_language_code @with_language_code end |
Class Method Details
.from_format(format) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/pubid/iso/rendering_style.rb', line 58 def self.from_format(format) case format when :ref_num_short RefNumShort.new when :ref_num_long RefNumLong.new when :ref_dated RefDated.new when :ref_dated_long RefDatedLong.new when :ref_undated RefUndated.new when :ref_undated_long RefUndatedLong.new else RefDatedLong.new # Default end end |
Instance Method Details
#render(identifier, with_edition: false) ⇒ Object
Render the identifier according to this style Subclasses should override if needed
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/pubid/iso/rendering_style.rb', line 18 def render(identifier, with_edition: false) parts = [] # Publisher portion parts << identifier.publisher_portion( lang: :en, stage_format_long: stage_format_long, ) # Number portion parts << identifier.number_portion( lang_single: single_char_language?, with_date: with_date, ) # Edition portion (if requested) if with_edition && identifier.edition && (identifier.edition.number || identifier.edition.original_text) parts << identifier.edition_portion(lang: :en) end result = parts.compact.join(" ") # Language portion (if applicable) # CRITICAL: with_edition=true should ALWAYS use multi-char language codes (en, fr, ru, etc.) # even if the original parsed format was single-char (E, F, R, etc.) if identifier.languages&.any? && with_language_code != :none use_single_char = with_edition ? false : single_char_language? result << identifier.language_portion(lang_single: use_single_char) end # All parts notation (if applicable) result << " (all parts)" if identifier.class.attributes.key?(:all_parts) && identifier.all_parts result end |
#single_char_language? ⇒ Boolean
54 55 56 |
# File 'lib/pubid/iso/rendering_style.rb', line 54 def single_char_language? with_language_code == :single end |