Class: Relaton::Cli::Command
- Inherits:
-
Thor
- Object
- Thor
- Relaton::Cli::Command
- Defined in:
- lib/relaton/cli/command.rb
Instance Method Summary collapse
- #concatenate(source_dir, outfile) ⇒ Object
-
#convert(file) ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/MethodLength.
- #extract(source_dir, outdir) ⇒ Object
- #fetch(code) ⇒ Object
- #split(source, outdir) ⇒ Object
- #xml2html(file, style = nil, template = nil) ⇒ Object
- #xml2yaml(filename) ⇒ Object
- #yaml2html(file, style = nil, template = nil) ⇒ Object
- #yaml2xml(filename) ⇒ Object
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, ) 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?([:format]) item.to_hash.to_yaml else item.send "to_#{[:format]}" end ext = case [:format] when "bibtex" then "bib" when "asciibib" then "adoc" else [:format] end output = [: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, ) 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, ) || ) 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, ) 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, ) 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, ) end |