Class: Relaton::Cli::Command

Inherits:
Thor
  • Object
show all
Defined in:
lib/relaton/cli/command.rb

Instance Method Summary collapse

Instance Method Details

#concatenate(source_dir, outfile) ⇒ Object



43
44
45
# File 'lib/relaton/cli/command.rb', line 43

def concatenate(source_dir, outfile)
  Relaton::Cli::RelatonFile.concatenate(source_dir, outfile, options)
end

#convert(file) ⇒ Object

rubocop:disable Metrics/AbcSize,Metrics/MethodLength



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/relaton/cli/command.rb', line 123

def convert(file) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
  xml = Nokogiri::XML(File.read(file, encoding: "UTF-8"))
  item = Relaton::Cli.parse_xml xml
  result = if /yaml|yml/.match?(options[:format])
             item.to_hash.to_yaml
           else item.send "to_#{options[:format]}"
           end
  ext = case options[:format]
        when "bibtex" then "bib"
        when "asciibib" then "adoc"
        else options[:format]
        end
  output = options[:output] || file.sub(/(?<=\.)[^\.]+$/, ext)
  File.write output, result, encoding: "UTF-8"
end

#extract(source_dir, outdir) ⇒ Object



29
30
31
# File 'lib/relaton/cli/command.rb', line 29

def extract(source_dir, outdir)
  Relaton::Cli::RelatonFile.extract(source_dir, outdir, options)
end

#fetch(code) ⇒ Object



18
19
20
21
22
# File 'lib/relaton/cli/command.rb', line 18

def fetch(code)
  Relaton.db
  io = IO.new(STDOUT.fcntl(::Fcntl::F_DUPFD), mode: "w:UTF-8")
  io.puts(fetch_document(code, options) || supported_type_message)
end

#split(source, outdir) ⇒ Object



54
55
56
# File 'lib/relaton/cli/command.rb', line 54

def split(source, outdir)
  Relaton::Cli::RelatonFile.split(source, outdir, options)
end

#xml2html(file, style = nil, template = nil) ⇒ Object



101
102
103
# File 'lib/relaton/cli/command.rb', line 101

def xml2html(file, style = nil, template = nil)
  Relaton::Cli::XMLConvertor.to_html(file, style, template)
end

#xml2yaml(filename) ⇒ Object



88
89
90
# File 'lib/relaton/cli/command.rb', line 88

def xml2yaml(filename)
  Relaton::Cli::XMLConvertor.to_yaml(filename, options)
end

#yaml2html(file, style = nil, template = nil) ⇒ Object



114
115
116
# File 'lib/relaton/cli/command.rb', line 114

def yaml2html(file, style = nil, template = nil)
  Relaton::Cli::YAMLConvertor.to_html(file, style, template)
end

#yaml2xml(filename) ⇒ Object



71
72
73
# File 'lib/relaton/cli/command.rb', line 71

def yaml2xml(filename)
  Relaton::Cli::YAMLConvertor.to_xml(filename, options)
end