Class: Pubid::Rendering::RenderingContext
- Inherits:
-
Object
- Object
- Pubid::Rendering::RenderingContext
- Defined in:
- lib/pubid/rendering/context.rb
Overview
Context object for flavor-specific and format-specific rendering rules
Encapsulates rendering rules that vary between flavors and between output formats (human-readable, URN, MR string). Components receive this context and render themselves accordingly — renderers and URN generators never reach into component internals.
Instance Attribute Summary collapse
-
#annotated ⇒ Object
readonly
Returns the value of attribute annotated.
-
#default_type_abbr ⇒ Object
readonly
Returns the value of attribute default_type_abbr.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#lang ⇒ Object
readonly
Returns the value of attribute lang.
-
#lang_single ⇒ Object
readonly
Returns the value of attribute lang_single.
-
#stage_format_long ⇒ Object
readonly
Returns the value of attribute stage_format_long.
-
#stage_separator ⇒ Object
readonly
Returns the value of attribute stage_separator.
-
#stage_separator_with_copublisher ⇒ Object
readonly
Returns the value of attribute stage_separator_with_copublisher.
-
#type_separator ⇒ Object
readonly
Returns the value of attribute type_separator.
-
#type_separator_with_prefix ⇒ Object
readonly
Returns the value of attribute type_separator_with_prefix.
-
#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
- .from_format(format) ⇒ Object
-
.iec ⇒ RenderingContext
IEC rendering context singleton.
-
.iso ⇒ RenderingContext
ISO rendering context singleton.
-
.nist ⇒ RenderingContext
NIST rendering context singleton.
- .ref_dated ⇒ Object
- .ref_num_long ⇒ Object
-
.ref_num_short ⇒ Object
Format factory methods — replace RenderingStyle hierarchy.
- .ref_undated ⇒ Object
- .ref_undated_long ⇒ Object
-
.urn ⇒ RenderingContext
URN rendering context: components emit URN-format fragments.
Instance Method Summary collapse
- #human? ⇒ Boolean
-
#initialize(format: :human, stage_separator: "/", stage_separator_with_copublisher: " ", type_separator: "/", type_separator_with_prefix: " ", default_type_abbr: "IS", lang: :en, lang_single: false, with_language_code: :none, stage_format_long: false, with_date: true, annotated: false) ⇒ RenderingContext
constructor
A new instance of RenderingContext.
- #mr? ⇒ Boolean
-
#should_render_type?(type_abbr) ⇒ Boolean
Check if type should be rendered (not default).
-
#stage_separator_for(has_copublisher:) ⇒ String
Get the appropriate stage separator based on whether there’s a copublisher.
-
#type_separator_for(has_prefix:) ⇒ String
Get the appropriate type separator based on whether there’s a prefix.
- #urn? ⇒ Boolean
Constructor Details
#initialize(format: :human, stage_separator: "/", stage_separator_with_copublisher: " ", type_separator: "/", type_separator_with_prefix: " ", default_type_abbr: "IS", lang: :en, lang_single: false, with_language_code: :none, stage_format_long: false, with_date: true, annotated: false) ⇒ RenderingContext
Returns a new instance of RenderingContext.
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 |
# File 'lib/pubid/rendering/context.rb', line 26 def initialize(format: :human, stage_separator: "/", stage_separator_with_copublisher: " ", type_separator: "/", type_separator_with_prefix: " ", default_type_abbr: "IS", lang: :en, lang_single: false, with_language_code: :none, stage_format_long: false, with_date: true, annotated: false) @format = format @stage_separator = stage_separator @stage_separator_with_copublisher = stage_separator_with_copublisher @type_separator = type_separator @type_separator_with_prefix = type_separator_with_prefix @default_type_abbr = default_type_abbr @lang = lang @lang_single = lang_single @with_language_code = with_language_code @stage_format_long = stage_format_long @with_date = with_date @annotated = annotated end |
Instance Attribute Details
#annotated ⇒ Object (readonly)
Returns the value of attribute annotated.
12 13 14 |
# File 'lib/pubid/rendering/context.rb', line 12 def annotated @annotated end |
#default_type_abbr ⇒ Object (readonly)
Returns the value of attribute default_type_abbr.
12 13 14 |
# File 'lib/pubid/rendering/context.rb', line 12 def default_type_abbr @default_type_abbr end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
12 13 14 |
# File 'lib/pubid/rendering/context.rb', line 12 def format @format end |
#lang ⇒ Object (readonly)
Returns the value of attribute lang.
12 13 14 |
# File 'lib/pubid/rendering/context.rb', line 12 def lang @lang end |
#lang_single ⇒ Object (readonly)
Returns the value of attribute lang_single.
12 13 14 |
# File 'lib/pubid/rendering/context.rb', line 12 def lang_single @lang_single end |
#stage_format_long ⇒ Object (readonly)
Returns the value of attribute stage_format_long.
12 13 14 |
# File 'lib/pubid/rendering/context.rb', line 12 def stage_format_long @stage_format_long end |
#stage_separator ⇒ Object (readonly)
Returns the value of attribute stage_separator.
12 13 14 |
# File 'lib/pubid/rendering/context.rb', line 12 def stage_separator @stage_separator end |
#stage_separator_with_copublisher ⇒ Object (readonly)
Returns the value of attribute stage_separator_with_copublisher.
12 13 14 |
# File 'lib/pubid/rendering/context.rb', line 12 def stage_separator_with_copublisher @stage_separator_with_copublisher end |
#type_separator ⇒ Object (readonly)
Returns the value of attribute type_separator.
12 13 14 |
# File 'lib/pubid/rendering/context.rb', line 12 def type_separator @type_separator end |
#type_separator_with_prefix ⇒ Object (readonly)
Returns the value of attribute type_separator_with_prefix.
12 13 14 |
# File 'lib/pubid/rendering/context.rb', line 12 def type_separator_with_prefix @type_separator_with_prefix end |
#with_date ⇒ Object (readonly)
Returns the value of attribute with_date.
12 13 14 |
# File 'lib/pubid/rendering/context.rb', line 12 def with_date @with_date end |
#with_language_code ⇒ Object (readonly)
Returns the value of attribute with_language_code.
12 13 14 |
# File 'lib/pubid/rendering/context.rb', line 12 def with_language_code @with_language_code end |
Class Method Details
.from_format(format) ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/pubid/rendering/context.rb', line 155 def self.from_format(format) case format when :ref_num_short then ref_num_short when :ref_num_long then ref_num_long when :ref_dated then ref_dated when :ref_dated_long then ref_dated when :ref_undated then ref_undated when :ref_undated_long then ref_undated_long else ref_dated end end |
.iec ⇒ RenderingContext
IEC rendering context singleton
102 103 104 105 106 107 108 109 110 |
# File 'lib/pubid/rendering/context.rb', line 102 def self.iec @iec ||= new( stage_separator: "/", stage_separator_with_copublisher: " ", type_separator: "/", type_separator_with_prefix: " ", default_type_abbr: "IS", ) end |
.iso ⇒ RenderingContext
ISO rendering context singleton
90 91 92 93 94 95 96 97 98 |
# File 'lib/pubid/rendering/context.rb', line 90 def self.iso @iso ||= new( stage_separator: "/", stage_separator_with_copublisher: " ", type_separator: "/", type_separator_with_prefix: " ", default_type_abbr: "IS", ) end |
.nist ⇒ RenderingContext
NIST rendering context singleton
114 115 116 117 118 119 120 121 122 |
# File 'lib/pubid/rendering/context.rb', line 114 def self.nist @nist ||= new( stage_separator: "", stage_separator_with_copublisher: " ", type_separator: " ", type_separator_with_prefix: " ", default_type_abbr: "", ) end |
.ref_dated ⇒ Object
140 141 142 143 |
# File 'lib/pubid/rendering/context.rb', line 140 def self.ref_dated new(with_language_code: :none, stage_format_long: false, with_date: true) end |
.ref_num_long ⇒ Object
136 137 138 |
# File 'lib/pubid/rendering/context.rb', line 136 def self.ref_num_long new(with_language_code: :iso, stage_format_long: true, with_date: true) end |
.ref_num_short ⇒ Object
Format factory methods — replace RenderingStyle hierarchy
131 132 133 134 |
# File 'lib/pubid/rendering/context.rb', line 131 def self.ref_num_short new(with_language_code: :single, stage_format_long: false, with_date: true) end |
.ref_undated ⇒ Object
145 146 147 148 |
# File 'lib/pubid/rendering/context.rb', line 145 def self.ref_undated new(with_language_code: :none, stage_format_long: false, with_date: false) end |
.ref_undated_long ⇒ Object
150 151 152 153 |
# File 'lib/pubid/rendering/context.rb', line 150 def self.ref_undated_long new(with_language_code: :none, stage_format_long: true, with_date: false) end |
.urn ⇒ RenderingContext
URN rendering context: components emit URN-format fragments
126 127 128 |
# File 'lib/pubid/rendering/context.rb', line 126 def self.urn @urn ||= new(format: :urn) end |
Instance Method Details
#human? ⇒ Boolean
56 57 58 |
# File 'lib/pubid/rendering/context.rb', line 56 def human? @format == :human end |
#mr? ⇒ Boolean
60 61 62 |
# File 'lib/pubid/rendering/context.rb', line 60 def mr? @format == :mr end |
#should_render_type?(type_abbr) ⇒ Boolean
Check if type should be rendered (not default)
84 85 86 |
# File 'lib/pubid/rendering/context.rb', line 84 def should_render_type?(type_abbr) type_abbr && type_abbr != @default_type_abbr end |
#stage_separator_for(has_copublisher:) ⇒ String
Get the appropriate stage separator based on whether there’s a copublisher
68 69 70 |
# File 'lib/pubid/rendering/context.rb', line 68 def stage_separator_for(has_copublisher:) has_copublisher ? @stage_separator_with_copublisher : @stage_separator end |
#type_separator_for(has_prefix:) ⇒ String
Get the appropriate type separator based on whether there’s a prefix
76 77 78 |
# File 'lib/pubid/rendering/context.rb', line 76 def type_separator_for(has_prefix:) has_prefix ? @type_separator_with_prefix : @type_separator end |
#urn? ⇒ Boolean
52 53 54 |
# File 'lib/pubid/rendering/context.rb', line 52 def urn? @format == :urn end |