Class: Pubid::Core::PatternDocGenerator
- Inherits:
-
Object
- Object
- Pubid::Core::PatternDocGenerator
- Defined in:
- lib/pubid/core/pattern_doc_generator.rb
Constant Summary collapse
- FLAVOR_NAMES =
{ "iso" => "ISO (International Organization for Standardization)", "iec" => "IEC (International Electrotechnical Commission)", "ieee" => "IEEE (Institute of Electrical and Electronics Engineers)", "nist" => "NIST (National Institute of Standards and Technology)", "cen" => "CEN (European Committee for Standardization)", "bsi" => "BSI (British Standards Institution)", "ccsds" => "CCSDS (Consultative Committee for Space Data Systems)", "itu" => "ITU (International Telecommunication Union)", "etsi" => "ETSI (European Telecommunications Standards Institute)", "jis" => "JIS (Japanese Industrial Standards)", "plateau" => "PLATEAU (Japanese urban planning standards)", "asme" => "ASME (American Society of Mechanical Engineers)", "astm" => "ASTM (ASTM International)", "ashrae" => "ASHRAE (American Society of Heating, Refrigerating and Air-Conditioning Engineers)", "api" => "API (American Petroleum Institute)", "cie" => "CIE (International Commission on Illumination)", "csa" => "CSA (Canadian Standards Association)", "idf" => "IDF (International Dairy Federation)", "oiml" => "OIML (International Organization of Legal Metrology)", "jcgm" => "JCGM (Joint Committee for Guides in Metrology)", "sae" => "SAE (SAE International)", "amca" => "AMCA (Air Movement and Control Association)", "ansi" => "ANSI (American National Standards Institute)", }.freeze
Instance Attribute Summary collapse
-
#flavor ⇒ Object
readonly
Returns the value of attribute flavor.
Class Method Summary collapse
-
.generate_cross_flavor_table(flavors) ⇒ Object
Cross-flavor comparison table.
Instance Method Summary collapse
- #collect_identifier_types ⇒ Object
- #generate ⇒ Object
- #has_update_codes? ⇒ Boolean
- #has_urn_generator? ⇒ Boolean
-
#initialize(flavor) ⇒ PatternDocGenerator
constructor
A new instance of PatternDocGenerator.
Constructor Details
#initialize(flavor) ⇒ PatternDocGenerator
Returns a new instance of PatternDocGenerator.
36 37 38 |
# File 'lib/pubid/core/pattern_doc_generator.rb', line 36 def initialize(flavor) @flavor = flavor end |
Instance Attribute Details
#flavor ⇒ Object (readonly)
Returns the value of attribute flavor.
8 9 10 |
# File 'lib/pubid/core/pattern_doc_generator.rb', line 8 def flavor @flavor end |
Class Method Details
.generate_cross_flavor_table(flavors) ⇒ Object
Cross-flavor comparison table
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'lib/pubid/core/pattern_doc_generator.rb', line 250 def self.generate_cross_flavor_table(flavors) lines = [] lines << "# PubID Identifier Pattern Cross-Flavor Comparison" lines << "" lines << "| Flavor | ID Types | Typed Stages | URN Support | Normalization |" lines << "|--------|----------|-------------|-------------|--------------|" flavors.sort.each do |f| gen = new(f) types = gen.collect_identifier_types.keys.length stages = gen.collect_identifier_types.values.sum do |t| t[:typed_stages].length end urn = gen.has_urn_generator? ? "Yes" : "No" norm = gen.has_update_codes? ? "Yes" : "No" lines << "| #{f.upcase} | #{types} | #{stages} | #{urn} | #{norm} |" end lines.join("\n") end |
Instance Method Details
#collect_identifier_types ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/pubid/core/pattern_doc_generator.rb', line 101 def collect_identifier_types types = {} idents_dir = File.join(__dir__, "..", "..", "pubid", flavor, "identifiers") return types unless Dir.exist?(idents_dir) Dir.glob(File.join(idents_dir, "*.rb")).each do |f| type_name = File.basename(f, ".rb").gsub("_", " ").split.map(&:capitalize).join(" ") class_path = "Pubid::#{flavor.capitalize}::Identifiers::#{type_name.gsub( ' ', '' )}" typed_stages = extract_typed_stages(f) types[type_name] = { class_path: class_path, typed_stages: typed_stages, } end types rescue StandardError types end |
#generate ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/pubid/core/pattern_doc_generator.rb', line 40 def generate lines = [] lines << "# #{flavor_upcase} Identifier Patterns" lines << "" lines << flavor_description lines << "" lines << "## Entry Point" lines << "" lines << "```ruby" lines << "require 'pubid/#{flavor}'" lines << "id = Pubid::#{flavor.capitalize}.parse(\"...\")" lines << "```" lines << "" identifier_types = collect_identifier_types if identifier_types.any? lines << "## Identifier Types" lines << "" identifier_types.each do |type_name, type_info| lines << "### #{type_name}" lines << "" lines << "**Class:** `#{type_info[:class_path]}`" lines << "" if type_info[:typed_stages].any? lines << "#### Typed Stages" lines << "" lines << stage_table(type_info[:typed_stages]) lines << "" end end end fixtures = collect_fixtures if fixtures.any? lines << "## Examples" lines << "" lines << fixture_table(fixtures) lines << "" end urn_gen = has_urn_generator? lines << "## URN Support" lines << "" lines << urn_gen ? "Yes - `id.to_urn` generates URN output." : "No URN generator defined." lines << "" update_codes = has_update_codes? lines << "## Pre-parse Normalization" lines << "" lines << if update_codes "See `data/#{flavor}/update_codes.yaml` for legacy format mappings." else "No normalization rules defined." end lines << "" lines.join("\n") end |
#has_update_codes? ⇒ Boolean
133 134 135 136 |
# File 'lib/pubid/core/pattern_doc_generator.rb', line 133 def has_update_codes? File.exist?(File.join(__dir__, "..", "..", "..", "data", flavor, "update_codes.yaml")) end |
#has_urn_generator? ⇒ Boolean
128 129 130 131 |
# File 'lib/pubid/core/pattern_doc_generator.rb', line 128 def has_urn_generator? File.exist?(File.join(__dir__, "..", "..", "pubid", flavor, "urn_generator.rb")) end |