Class: Glossarist::Agent::Iho::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/glossarist/agent/iho/generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cache_dir, output_path) ⇒ Generator

Returns a new instance of Generator.



11
12
13
14
15
# File 'lib/glossarist/agent/iho/generator.rb', line 11

def initialize(cache_dir, output_path)
  @cache_dir = cache_dir
  @output_path = output_path
  FileUtils.mkdir_p(@output_path)
end

Instance Attribute Details

#language_tablesObject

Returns the value of attribute language_tables.



9
10
11
# File 'lib/glossarist/agent/iho/generator.rb', line 9

def language_tables
  @language_tables
end

#simple_conceptsObject

Returns the value of attribute simple_concepts.



9
10
11
# File 'lib/glossarist/agent/iho/generator.rb', line 9

def simple_concepts
  @simple_concepts
end

Instance Method Details

#build_simple_conceptsObject



44
45
46
47
48
49
50
51
# File 'lib/glossarist/agent/iho/generator.rb', line 44

def build_simple_concepts
  return @simple_concepts if @simple_concepts

  @simple_concepts = {}
  build_english_concepts
  build_other_language_concepts
  @simple_concepts
end

#collectionObject



17
18
19
20
21
22
23
24
25
# File 'lib/glossarist/agent/iho/generator.rb', line 17

def collection
  return @collection if @collection

  parse_language_tables
  build_simple_concepts
  convert_to_glossarist

  @collection
end

#convert_to_glossaristObject



53
54
55
56
# File 'lib/glossarist/agent/iho/generator.rb', line 53

def convert_to_glossarist
  @collection = ::Glossarist::ManagedConceptCollection.new
  @collection.managed_concepts = create_managed_concepts
end

#parse_language_tablesObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/glossarist/agent/iho/generator.rb', line 27

def parse_language_tables
  return @language_tables if @language_tables

  @language_tables = {}
  Dir.glob(File.join(@cache_dir, "*.csv")).map do |file|
    lang_code = Downloader.lang_code_by_filename(File.basename(file))

    table = BilingualTable.new(file_path: file, lang_code: lang_code).tap do |table|
      table.process
    end

    @language_tables[lang_code] = table
  end

  @language_tables
end

#save_to_filesObject



58
59
60
61
# File 'lib/glossarist/agent/iho/generator.rb', line 58

def save_to_files
  collection.save_to_files(@output_path)
  puts "Concepts generated and saved to #{@output_path}"
end