Class: Glossarist::Validation::Rules::GcrContext
- Inherits:
-
Object
- Object
- Glossarist::Validation::Rules::GcrContext
- Defined in:
- lib/glossarist/validation/rules/gcr_context.rb
Instance Attribute Summary collapse
-
#zip_path ⇒ Object
readonly
Returns the value of attribute zip_path.
Instance Method Summary collapse
- #actual_languages ⇒ Object
- #add_concept(concept) ⇒ Object
- #asset_index ⇒ Object
- #bibliography_index ⇒ Object
- #concept_ids ⇒ Object
- #concepts ⇒ Object
- #declared_languages ⇒ Object
- #gcr? ⇒ Boolean
-
#initialize(zip_path) ⇒ GcrContext
constructor
A new instance of GcrContext.
- #localization_index ⇒ Object
- #metadata ⇒ Object
- #read_zip_file(name) ⇒ Object
- #referenced_l10n_uuids ⇒ Object
- #zip_entries ⇒ Object
Constructor Details
#initialize(zip_path) ⇒ GcrContext
Returns a new instance of GcrContext.
11 12 13 14 15 16 17 18 |
# File 'lib/glossarist/validation/rules/gcr_context.rb', line 11 def initialize(zip_path) @zip_path = zip_path @accumulated_concepts = [] @metadata = nil @bibliography_index = nil @asset_index = nil @zip_entries = nil end |
Instance Attribute Details
#zip_path ⇒ Object (readonly)
Returns the value of attribute zip_path.
9 10 11 |
# File 'lib/glossarist/validation/rules/gcr_context.rb', line 9 def zip_path @zip_path end |
Instance Method Details
#actual_languages ⇒ Object
58 59 60 61 62 |
# File 'lib/glossarist/validation/rules/gcr_context.rb', line 58 def actual_languages @actual_languages ||= concepts.flat_map do |c| c.localizations.map(&:language_code) end.compact.uniq.sort end |
#add_concept(concept) ⇒ Object
20 21 22 23 |
# File 'lib/glossarist/validation/rules/gcr_context.rb', line 20 def add_concept(concept) @accumulated_concepts << concept @concept_ids = nil end |
#asset_index ⇒ Object
50 51 52 |
# File 'lib/glossarist/validation/rules/gcr_context.rb', line 50 def asset_index @asset_index ||= AssetIndex.build_from_zip(@zip_path) end |
#bibliography_index ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/glossarist/validation/rules/gcr_context.rb', line 42 def bibliography_index @bibliography_index ||= BibliographyIndex.build_from_yaml( concepts, bibliography_yaml: read_zip_file("bibliography.yaml"), images_yaml: read_zip_file("images.yaml"), ) end |
#concept_ids ⇒ Object
29 30 31 |
# File 'lib/glossarist/validation/rules/gcr_context.rb', line 29 def concept_ids @concept_ids ||= concepts.filter_map { |c| c.data&.id&.to_s }.to_set end |
#concepts ⇒ Object
25 26 27 |
# File 'lib/glossarist/validation/rules/gcr_context.rb', line 25 def concepts @accumulated_concepts end |
#declared_languages ⇒ Object
54 55 56 |
# File 'lib/glossarist/validation/rules/gcr_context.rb', line 54 def declared_languages &.languages || [] end |
#gcr? ⇒ Boolean
78 79 80 |
# File 'lib/glossarist/validation/rules/gcr_context.rb', line 78 def gcr? true end |
#localization_index ⇒ Object
70 71 72 |
# File 'lib/glossarist/validation/rules/gcr_context.rb', line 70 def localization_index {} end |
#metadata ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/glossarist/validation/rules/gcr_context.rb', line 33 def @metadata ||= Zip::File.open(@zip_path) do |zf| entry = zf.find_entry("metadata.yaml") return nil unless entry GcrMetadata.from_yaml(entry.get_input_stream.read) end end |
#read_zip_file(name) ⇒ Object
82 83 84 85 86 87 |
# File 'lib/glossarist/validation/rules/gcr_context.rb', line 82 def read_zip_file(name) Zip::File.open(@zip_path) do |zf| entry = zf.find_entry(name) entry&.get_input_stream&.read end end |
#referenced_l10n_uuids ⇒ Object
74 75 76 |
# File 'lib/glossarist/validation/rules/gcr_context.rb', line 74 def referenced_l10n_uuids Set.new end |
#zip_entries ⇒ Object
64 65 66 67 68 |
# File 'lib/glossarist/validation/rules/gcr_context.rb', line 64 def zip_entries @zip_entries ||= Zip::File.open(@zip_path) do |zf| zf.entries.to_set(&:name) end end |