Class: Stepmod::Utils::TermsExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/stepmod/utils/terms_extractor.rb

Constant Summary collapse

ACCEPTED_STAGES =

TODO: we may want a command line option to override this in the future

%w(IS DIS FDIS TS)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stepmod_dir, stdout) ⇒ TermsExtractor

Returns a new instance of TermsExtractor.



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/stepmod/utils/terms_extractor.rb', line 29

def initialize(stepmod_dir, stdout)
  @stdout = stdout
  @stepmod_dir = stepmod_dir
  @stepmod_path = Pathname.new(stepmod_dir).realpath
  @general_concepts = []
  @resource_concepts = []
  @parsed_bibliography = []
  @part_concepts = []
  @part_resources = []
  @part_modules = []
  @encountered_terms = {}
end

Instance Attribute Details

#cvs_modeObject (readonly)

Returns the value of attribute cvs_mode.



13
14
15
# File 'lib/stepmod/utils/terms_extractor.rb', line 13

def cvs_mode
  @cvs_mode
end

#encountered_termsObject (readonly)

Returns the value of attribute encountered_terms.



13
14
15
# File 'lib/stepmod/utils/terms_extractor.rb', line 13

def encountered_terms
  @encountered_terms
end

#general_conceptsObject (readonly)

Returns the value of attribute general_concepts.



13
14
15
# File 'lib/stepmod/utils/terms_extractor.rb', line 13

def general_concepts
  @general_concepts
end

#parsed_bibliographyObject (readonly)

Returns the value of attribute parsed_bibliography.



13
14
15
# File 'lib/stepmod/utils/terms_extractor.rb', line 13

def parsed_bibliography
  @parsed_bibliography
end

#part_conceptsObject (readonly)

Returns the value of attribute part_concepts.



13
14
15
# File 'lib/stepmod/utils/terms_extractor.rb', line 13

def part_concepts
  @part_concepts
end

#part_modulesObject (readonly)

Returns the value of attribute part_modules.



13
14
15
# File 'lib/stepmod/utils/terms_extractor.rb', line 13

def part_modules
  @part_modules
end

#part_resourcesObject (readonly)

Returns the value of attribute part_resources.



13
14
15
# File 'lib/stepmod/utils/terms_extractor.rb', line 13

def part_resources
  @part_resources
end

#resource_conceptsObject (readonly)

Returns the value of attribute resource_concepts.



13
14
15
# File 'lib/stepmod/utils/terms_extractor.rb', line 13

def resource_concepts
  @resource_concepts
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



13
14
15
# File 'lib/stepmod/utils/terms_extractor.rb', line 13

def stdout
  @stdout
end

#stepmod_dirObject (readonly)

Returns the value of attribute stepmod_dir.



13
14
15
# File 'lib/stepmod/utils/terms_extractor.rb', line 13

def stepmod_dir
  @stepmod_dir
end

#stepmod_pathObject (readonly)

Returns the value of attribute stepmod_path.



13
14
15
# File 'lib/stepmod/utils/terms_extractor.rb', line 13

def stepmod_path
  @stepmod_path
end

Class Method Details

.call(stepmod_dir, stdout = STDOUT) ⇒ Object



25
26
27
# File 'lib/stepmod/utils/terms_extractor.rb', line 25

def self.call(stepmod_dir, stdout = STDOUT)
  new(stepmod_dir, stdout).call
end

Instance Method Details

#callObject



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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/stepmod/utils/terms_extractor.rb', line 57

def call
  # If we are using the stepmod CVS repository, provide the revision number per file
  @cvs_mode = if Dir.exists?(stepmod_path.join('CVS'))
    require 'ptools'
    # ptools provides File.which
    File.which("cvs")
  end

  log "INFO: STEPmod directory set to #{stepmod_dir}."

  if cvs_mode
    log "INFO: STEPmod directory is a CVS repository and will detect revisions."
    log "INFO: [CVS] Detecting file revisions can be slow, please be patient!"
  else
    log "INFO: STEPmod directory is not a CVS repository, skipping revision detection."
  end

  log "INFO: Detecting paths..."

  repo_index = Nokogiri::XML(File.read(stepmod_path.join('repository_index.xml'))).root

  files = []

  # add module paths
  repo_index.xpath('//module').each do |x|
    path = Pathname.new("#{stepmod_dir}/modules/#{x['name']}/module.xml")
    files << path if File.exists? path
  end

  # add resource_docs paths
  repo_index.xpath('//resource_doc').each do |x|
    path = Pathname.new("#{stepmod_dir}/resource_docs/#{x['name']}/resource.xml")
    files << path if File.exists? path
  end

  # add business_object_models paths
  repo_index.xpath('//business_object_model').each do |x|
    path = Pathname.new("#{stepmod_dir}/business_object_models/#{x['name']}/business_object_model.xml")
    files << path if File.exists? path
  end

  # add application_protocols paths
  repo_index.xpath('//application_protocol').each do |x|
    path = Pathname.new("#{stepmod_dir}/application_protocols/#{x['name']}/application_protocol.xml")
    files << path if File.exists? path
  end

  files.sort!.uniq!
  process_term_files(files)

  [
    general_concepts,
    resource_concepts,
    parsed_bibliography,
    part_concepts,
    part_resources,
    part_modules
  ]
end

#log(message) ⇒ Object



42
43
44
# File 'lib/stepmod/utils/terms_extractor.rb', line 42

def log message
  stdout.puts "[stepmod-utils] #{message}"
end

#term_special_category(bibdata) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'lib/stepmod/utils/terms_extractor.rb', line 46

def term_special_category(bibdata)
  case bibdata.part.to_i
  when 41,42,43,44,45,46,47,51
    true
  when [56..112]
    true
  else
    false
  end
end