Class: Pubid::Iec::RenderingStyle
- Inherits:
-
Object
- Object
- Pubid::Iec::RenderingStyle
- Defined in:
- lib/pubid/iec/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.
- #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/iec/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/iec/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/iec/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/iec/rendering_style.rb', line 8 def with_language_code @with_language_code end |
Class Method Details
.from_format(format) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/pubid/iec/rendering_style.rb', line 51 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
17 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 |
# File 'lib/pubid/iec/rendering_style.rb', line 17 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) if identifier.languages&.any? && with_language_code != :none result << identifier.language_portion(lang_single: single_char_language?) end result end |
#single_char_language? ⇒ Boolean
47 48 49 |
# File 'lib/pubid/iec/rendering_style.rb', line 47 def single_char_language? with_language_code == :single end |