Class: Logaling::ExternalGlossary

Inherits:
Object
  • Object
show all
Defined in:
lib/logaling/external_glossary.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.description(val = nil) ⇒ Object



50
51
52
# File 'lib/logaling/external_glossary.rb', line 50

def description val=nil
  @description ||= val
end

.external_glossariesObject



42
43
44
# File 'lib/logaling/external_glossary.rb', line 42

def external_glossaries
  @@external_glossaries ||= []
end

.get(external_glossary) ⇒ Object



36
37
38
39
40
# File 'lib/logaling/external_glossary.rb', line 36

def get(external_glossary)
  external_glossaries.detect{|c| c.inspect.include? external_glossary.camelize }.new
rescue NoMethodError
  raise Logaling::ExternalGlossaryNotFound
end

.inherited(subclass) ⇒ Object



28
29
30
# File 'lib/logaling/external_glossary.rb', line 28

def inherited(subclass)
  external_glossaries << subclass
end

.listObject



32
33
34
# File 'lib/logaling/external_glossary.rb', line 32

def list
  external_glossaries
end

.loadObject



22
23
24
25
26
# File 'lib/logaling/external_glossary.rb', line 22

def load
  Dir[File.join(File.dirname(__FILE__), "external_glossaries", "*.rb")].each do |file|
    require file
  end
end

.nameObject



46
47
48
# File 'lib/logaling/external_glossary.rb', line 46

def name
  self.to_s.underscore.gsub(/.*\//,'')
end

.output_format(*args) ⇒ Object



66
67
68
69
70
71
72
# File 'lib/logaling/external_glossary.rb', line 66

def output_format(*args)
  if args.empty?
    @output_format ||= "csv"
  else
    @output_format = args.first
  end
end

.source_language(val = nil) ⇒ Object



58
59
60
# File 'lib/logaling/external_glossary.rb', line 58

def source_language val=nil
  @source_language ||= val
end

.target_language(val = nil) ⇒ Object



62
63
64
# File 'lib/logaling/external_glossary.rb', line 62

def target_language val=nil
  @target_language ||= val
end

.url(val = nil) ⇒ Object



54
55
56
# File 'lib/logaling/external_glossary.rb', line 54

def url val=nil
  @url ||= val
end

Instance Method Details

#import(glossary = nil, url = nil) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/logaling/external_glossary.rb', line 75

def import(glossary=nil, url=nil)
  if glossary && url
    unless file_exists?(url)
      raise Logaling::GlossaryNotFound, "Failed open url/path <#{url}>"
    end
  end
  File.open(import_file_name(glossary), "w") do |output|
    output_format = self.class.output_format
    output_format = output_format.to_s if output_format.is_a?(Symbol)
    case output_format
    when "csv"
      if glossary
        convert_to_csv(CSV.new(output), glossary, url)
      else
        convert_to_csv(CSV.new(output))
      end
    else
      raise UnsupportedFormat, "unsupported format: <#{output_format}>"
    end
  end
end