glossarist-new 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6c97457297f94e65b52da9de5fd9dc620f3722034e9a97dae80c81736333cf7d
4
- data.tar.gz: e8716f64a5cb9d2e84f752540854219a6ffe406fc46140158274fc135a002da0
3
+ metadata.gz: 33417ab36e59957a55a83d33feb67f9657d1a790c72200a113a8da5d5da30dbb
4
+ data.tar.gz: 394244acd5674b48b66316576472f23bab6d9ffb9c8d9cac6febe592827d75a7
5
5
  SHA512:
6
- metadata.gz: 2f9db6e9f0f5e716c9810d44f06fd14d77140aa060b9004dbc900c2766be1bb08733789e0619d8cda633c18158ddf931b943cd9a5c4d6c025240f71453f351e4
7
- data.tar.gz: 28c854fab76b67814180a2da7043ecb8072aea4828c9bcba92cf2b45ae57af5680733532837d46427a8bfd0d2834b965a04b51791010e50b214243ab27d7b7bc
6
+ metadata.gz: d855e52b2d3d48a1b2a7c46190a229af9e0597f2b971e18a3d73ad3194387fba2f9a8d270abe8840f59bd9940d4802ec6b2dcaf8b9422f425dcb7fd172a66a8a
7
+ data.tar.gz: 75414f5177abe52d0fa160d5cb5769ea27ba175f89cfa6e7aa2c6fdb8c3d26e03e00181b310d85e3e0e6dba93cfbbeab0c61dca9e3f74260bc77706cdd6b94ac
data/README.adoc CHANGED
@@ -1,5 +1,28 @@
1
1
  = Glossarist
2
2
 
3
+ == Commands
4
+
5
+ generate_latex: Convert Concepts to Latex format
6
+
7
+ === Usage:
8
+ glossarist generate_latex p, --concepts-path=CONCEPTS_PATH
9
+
10
+ === Options:
11
+ [cols="1,1"]
12
+ |===
13
+ |p, --concepts-path
14
+ |Path to yaml concepts directory
15
+
16
+ |l, --latex-concepts
17
+ |File path having list of concepts that should be converted to LATEX format. If not provided all the concepts will be converted to the latex format
18
+
19
+ |o, --output-file
20
+ |Output file path. By default the output will pe printed to the console
21
+
22
+ |e, --extra-attributes
23
+ |List of extra attributes that are not in standard Glossarist Concept model. eg -e one two three
24
+ |===
25
+
3
26
  == Credits
4
27
 
5
28
  This gem is developed, maintained and funded by
data/exe/glossarist ADDED
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative "../lib/glossarist"
4
+
5
+ class GlossaristCommand < Thor
6
+ desc "generate_latex", "Convert Concepts to Latex format"
7
+
8
+ option :concepts_path, aliases: :p, required: true, desc: "Path to yaml concepts directory"
9
+ option :latex_concepts, aliases: :l, desc: "File path having list of concepts that should be converted to LATEX format. If not provided all the concepts will be converted to the latex format"
10
+ option :output_file, aliases: :o, desc: "Output file path. By default the output will pe printed to the console"
11
+ option :extra_attributes, aliases: :e, type: :array, desc: "List of extra attributes that are not in standard Glossarist Concept model"
12
+ def generate_latex
13
+ assets = []
14
+ latex_concepts_file = options[:latex_concepts]
15
+
16
+ if options[:extra_attributes]
17
+ Glossarist.configure do |config|
18
+ config.register_extension_attributes(options[:extra_attributes])
19
+ end
20
+ end
21
+
22
+ concept_set = Glossarist::ConceptSet.new(options[:concepts_path], assets)
23
+ latex_str = concept_set.to_latex(latex_concepts_file)
24
+
25
+ output_file_path = options[:output_file]
26
+ if output_file_path
27
+ File.open(output_file_path, "w") do |file|
28
+ file.puts latex_str
29
+ end
30
+ else
31
+ puts latex_str
32
+ end
33
+ end
34
+
35
+ def method_missing(*args)
36
+ warn "No method found named: #{args[0]}"
37
+ warn "Run with `--help` or `-h` to see available options"
38
+ exit 1
39
+ end
40
+
41
+ def respond_to_missing?
42
+ true
43
+ end
44
+
45
+ def self.exit_on_failure?
46
+ true
47
+ end
48
+ end
49
+
50
+ GlossaristCommand.start(ARGV)
data/glossarist.gemspec CHANGED
@@ -31,6 +31,7 @@ Gem::Specification.new do |spec|
31
31
  spec.require_paths = ["lib"]
32
32
 
33
33
  spec.add_dependency "relaton", "~>1.13.0"
34
+ spec.add_dependency "thor"
34
35
 
35
36
  spec.add_development_dependency "pry", "~> 0.14.0"
36
37
  spec.add_development_dependency "rake", "~> 13.0"
@@ -40,12 +40,16 @@ module Glossarist
40
40
  # @return [Array<DetailedDefinition>]
41
41
  attr_reader :examples
42
42
 
43
+ # Contains list of extended attributes
44
+ attr_accessor :extension_attributes
45
+
43
46
  def initialize(*)
44
47
  @localizations = {}
45
48
  @sources = []
46
49
  @related = []
47
50
  @notes = []
48
51
  @designations = []
52
+ @extension_attributes = {}
49
53
 
50
54
  super
51
55
  end
@@ -122,7 +126,7 @@ module Glossarist
122
126
 
123
127
  hash.values
124
128
  .grep(Hash)
125
- .map { |subhash| LocalizedConcept.from_h(subhash) rescue nil }
129
+ .map { |subhash| Config.class_for(:localized_concept).from_h(subhash) rescue nil }
126
130
  .compact
127
131
 
128
132
  concept.related = hash.dig("related") || []
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "singleton"
4
+
5
+ module Glossarist
6
+ class Config
7
+ include Singleton
8
+
9
+ DEFAULT_CLASSES = {
10
+ localized_concept: Glossarist::LocalizedConcept,
11
+ }.freeze
12
+
13
+ attr_reader :registered_classes
14
+
15
+ def initialize
16
+ @registered_classes = DEFAULT_CLASSES.dup
17
+ @extension_attributes = []
18
+ end
19
+
20
+ def class_for(name)
21
+ @registered_classes[name.to_sym]
22
+ end
23
+
24
+ def register_class(class_name, klass)
25
+ @registered_classes[class_name] = klass
26
+ end
27
+
28
+ def extension_attributes
29
+ @extension_attributes
30
+ end
31
+
32
+ def register_extension_attributes(attributes)
33
+ @extension_attributes = attributes
34
+ end
35
+
36
+ class << self
37
+ def class_for(name)
38
+ self.instance.class_for(name)
39
+ end
40
+
41
+ def extension_attributes
42
+ self.instance.extension_attributes
43
+ end
44
+
45
+ def register_class(class_name, klass)
46
+ self.instance.register_class(class_name, klass)
47
+ end
48
+
49
+ def register_extension_attributes(attributes)
50
+ self.register_extension_attributes(attributes)
51
+ end
52
+ end
53
+ end
54
+ end
@@ -44,7 +44,7 @@ module Glossarist
44
44
  "review_date" => review_date,
45
45
  "review_decision_date" => review_decision_date,
46
46
  "review_decision_event" => review_decision_event,
47
- }.compact)
47
+ }.compact).merge(@extension_attributes)
48
48
  end
49
49
 
50
50
  def self.from_h(hash)
@@ -36,7 +36,7 @@ module Glossarist
36
36
  end
37
37
 
38
38
  def localized_concepts=(localized_concepts_hash)
39
- @localized_concepts = localized_concepts_hash.map { |l| LocalizedConcept.new(l) }.compact
39
+ @localized_concepts = localized_concepts_hash.map { |l| Config.class_for(:localized_concept).new(l) }.compact
40
40
 
41
41
  @localized_concepts.each do |l|
42
42
  add_l10n(l)
@@ -18,8 +18,12 @@ module Glossarist
18
18
  def set_attribute(name, value)
19
19
  public_send("#{name}=", value)
20
20
  rescue NoMethodError
21
- raise ArgumentError, "#{self.class.name} does not have " +
22
- "attribute #{name} defined or the attribute is read only."
21
+ if Config.extension_attributes.include?(name)
22
+ extension_attributes[name] = value
23
+ else
24
+ raise ArgumentError, "#{self.class.name} does not have " +
25
+ "attribute #{name} defined or the attribute is read only."
26
+ end
23
27
  end
24
28
 
25
29
  def self.from_h(hash)
@@ -4,5 +4,5 @@
4
4
  #
5
5
 
6
6
  module Glossarist
7
- VERSION = "1.0.2"
7
+ VERSION = "1.0.4"
8
8
  end
data/lib/glossarist.rb CHANGED
@@ -4,6 +4,7 @@
4
4
  #
5
5
 
6
6
  require "psych"
7
+ require "thor"
7
8
 
8
9
  require_relative "glossarist/utilities"
9
10
  require_relative "glossarist/version"
@@ -28,8 +29,16 @@ require_relative "glossarist/non_verb_rep"
28
29
 
29
30
  require_relative "glossarist/collections"
30
31
 
32
+ require_relative "glossarist/config"
33
+
31
34
  module Glossarist
32
35
  class Error < StandardError; end
33
36
  class InvalidTypeError < StandardError; end
34
37
  # Your code goes here...
38
+
39
+ def self.configure
40
+ config = Glossarist::Config.instance
41
+
42
+ yield(config) if block_given?
43
+ end
35
44
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glossarist-new
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-01 00:00:00.000000000 Z
11
+ date: 2023-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: relaton
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.13.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: pry
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -69,7 +83,8 @@ dependencies:
69
83
  description:
70
84
  email:
71
85
  - open.source@ribose.com
72
- executables: []
86
+ executables:
87
+ - glossarist
73
88
  extensions: []
74
89
  extra_rdoc_files: []
75
90
  files:
@@ -84,6 +99,7 @@ files:
84
99
  - README.adoc
85
100
  - Rakefile
86
101
  - config.yml
102
+ - exe/glossarist
87
103
  - glossarist.gemspec
88
104
  - lib/glossarist.rb
89
105
  - lib/glossarist/asset.rb
@@ -97,6 +113,7 @@ files:
97
113
  - lib/glossarist/concept_manager.rb
98
114
  - lib/glossarist/concept_set.rb
99
115
  - lib/glossarist/concept_source.rb
116
+ - lib/glossarist/config.rb
100
117
  - lib/glossarist/designation.rb
101
118
  - lib/glossarist/designation/abbreviation.rb
102
119
  - lib/glossarist/designation/base.rb