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
- #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 19 |
# File 'lib/glossarist/validation/rules/gcr_context.rb', line 11 def initialize(zip_path) @zip_path = zip_path @metadata = nil @concepts = nil @bibliography_index = nil @asset_index = nil @zip_entries = nil @localization_index = 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
59 60 61 62 63 |
# File 'lib/glossarist/validation/rules/gcr_context.rb', line 59 def actual_languages @actual_languages ||= concepts.flat_map do |c| c.localizations.map(&:language_code) end.compact.uniq.sort end |
#asset_index ⇒ Object
51 52 53 |
# File 'lib/glossarist/validation/rules/gcr_context.rb', line 51 def asset_index @asset_index ||= AssetIndex.build_from_zip(@zip_path) end |
#bibliography_index ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/glossarist/validation/rules/gcr_context.rb', line 43 def bibliography_index @bibliography_index ||= begin bib_yaml = read_zip_file("bibliography.yaml") BibliographyIndex.build_from_concepts(concepts, bibliography_yaml: bib_yaml) end end |
#concept_ids ⇒ Object
30 31 32 |
# File 'lib/glossarist/validation/rules/gcr_context.rb', line 30 def concept_ids @concept_ids ||= concepts.filter_map { |c| c.data&.id&.to_s }.to_set end |
#concepts ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/glossarist/validation/rules/gcr_context.rb', line 21 def concepts @concepts ||= begin pkg = GcrPackage.load(@zip_path) pkg.concepts rescue StandardError [] end end |
#declared_languages ⇒ Object
55 56 57 |
# File 'lib/glossarist/validation/rules/gcr_context.rb', line 55 def declared_languages &.languages || [] end |
#gcr? ⇒ Boolean
79 80 81 |
# File 'lib/glossarist/validation/rules/gcr_context.rb', line 79 def gcr? true end |
#localization_index ⇒ Object
71 72 73 |
# File 'lib/glossarist/validation/rules/gcr_context.rb', line 71 def localization_index {} end |
#metadata ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/glossarist/validation/rules/gcr_context.rb', line 34 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
83 84 85 86 87 88 |
# File 'lib/glossarist/validation/rules/gcr_context.rb', line 83 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
75 76 77 |
# File 'lib/glossarist/validation/rules/gcr_context.rb', line 75 def referenced_l10n_uuids Set.new end |
#zip_entries ⇒ Object
65 66 67 68 69 |
# File 'lib/glossarist/validation/rules/gcr_context.rb', line 65 def zip_entries @zip_entries ||= Zip::File.open(@zip_path) do |zf| zf.entries.to_set(&:name) end end |