Class: Relaton::Cli::Command

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

Constant Summary

Constants included from Relaton::Cli

VERSION

Instance Method Summary collapse

Methods included from Relaton::Cli

parse_xml, processor, relaton, start, version

Instance Method Details

#concatenate(source_dir, outfile) ⇒ Object



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

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

#convert(file) ⇒ Object

rubocop:disable Metrics/AbcSize,Metrics/MethodLength



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/relaton/cli/command.rb', line 131

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



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

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

#fetch(code) ⇒ Object



34
35
36
37
# File 'lib/relaton/cli/command.rb', line 34

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

#fetch_data(source) ⇒ Object



151
152
153
# File 'lib/relaton/cli/command.rb', line 151

def fetch_data(source)
  DataFetcher.fetch source, options
end

#split(source, outdir) ⇒ Object



64
65
66
# File 'lib/relaton/cli/command.rb', line 64

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

#versionObject



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

def version
  Relaton::Cli.version
end

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



110
111
112
# File 'lib/relaton/cli/command.rb', line 110

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

#xml2yaml(filename) ⇒ Object



98
99
100
# File 'lib/relaton/cli/command.rb', line 98

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

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



123
124
125
# File 'lib/relaton/cli/command.rb', line 123

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

#yaml2xml(filename) ⇒ Object



81
82
83
# File 'lib/relaton/cli/command.rb', line 81

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