Class: Paru::Info
- Inherits:
-
Object
- Object
- Paru::Info
- Defined in:
- lib/paru/info.rb
Overview
Information about pandoc
Instance Attribute Summary collapse
-
#data_dir ⇒ String
Pandoc’s default data directory.
-
#scripting_engine ⇒ String
Pandoc’s internal scripting engine, like “Lua 5.4”.
-
#version ⇒ Array<Integer>
Pandoc’s version, like [2, 18, 1].
Instance Method Summary collapse
-
#[](key) ⇒ Any
deprecated
Deprecated.
Use Info’s getters instead.
-
#initialize(path = 'pandoc') ⇒ Info
constructor
Create a new Info object.
Constructor Details
#initialize(path = 'pandoc') ⇒ Info
Create a new Info object
assumes it’s on the environment’s path.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/paru/info.rb', line 42 def initialize(path = 'pandoc') # Get pandoc's version information version_string = '' IO.popen("#{path} --version", 'r+') do |p| p.close_write version_string << p.read end # Extract the version as an array of integers, like SemVer. @version = version_string .match(/pandoc.* (\d+\.\d+.*)$/)[1] .split('.') .map(&:to_i) # Extract the data directory @data_dir = version_string.match(/User data directory: (.+)$/)[1] # Extract scripting engine @scripting_engine = version_string.match(/Scripting engine: (.+)$/)[1] rescue StandardError => e warn "Error extracting pandoc's information: #{e.message}" warn 'Using made up values instead.' @version ||= [2, 18] @data_dir ||= '.' @scripting_engine ||= 'Lua 5.4' end |
Instance Attribute Details
#data_dir ⇒ String
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 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 |
# File 'lib/paru/info.rb', line 35 class Info attr_reader :version, :data_dir, :scripting_engine # Create a new Info object # # @param path [String] the path to pandoc. Defaults to 'pandoc', i.e., # assumes it's on the environment's path. def initialize(path = 'pandoc') # Get pandoc's version information version_string = '' IO.popen("#{path} --version", 'r+') do |p| p.close_write version_string << p.read end # Extract the version as an array of integers, like SemVer. @version = version_string .match(/pandoc.* (\d+\.\d+.*)$/)[1] .split('.') .map(&:to_i) # Extract the data directory @data_dir = version_string.match(/User data directory: (.+)$/)[1] # Extract scripting engine @scripting_engine = version_string.match(/Scripting engine: (.+)$/)[1] rescue StandardError => e warn "Error extracting pandoc's information: #{e.message}" warn 'Using made up values instead.' @version ||= [2, 18] @data_dir ||= '.' @scripting_engine ||= 'Lua 5.4' end # Get pandoc's info by key like a Hash for backwards compatability. # # @deprecated Use Info's getters instead. # # @param key [String|Symbol] the key for the information to look up. # Info only supports keys 'version' and 'data_dir'. # @return [Any] Information associated with the key. # @raise [Error] for an unknown key. def [](key) case key when 'verion', :version version when 'data_dir', :data_dir data_dir when 'scripting_engine', :scripting_engine scripting_engine else throw Error.new "Info does not know key '#{key}'" end end end |
#scripting_engine ⇒ String
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 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 |
# File 'lib/paru/info.rb', line 35 class Info attr_reader :version, :data_dir, :scripting_engine # Create a new Info object # # @param path [String] the path to pandoc. Defaults to 'pandoc', i.e., # assumes it's on the environment's path. def initialize(path = 'pandoc') # Get pandoc's version information version_string = '' IO.popen("#{path} --version", 'r+') do |p| p.close_write version_string << p.read end # Extract the version as an array of integers, like SemVer. @version = version_string .match(/pandoc.* (\d+\.\d+.*)$/)[1] .split('.') .map(&:to_i) # Extract the data directory @data_dir = version_string.match(/User data directory: (.+)$/)[1] # Extract scripting engine @scripting_engine = version_string.match(/Scripting engine: (.+)$/)[1] rescue StandardError => e warn "Error extracting pandoc's information: #{e.message}" warn 'Using made up values instead.' @version ||= [2, 18] @data_dir ||= '.' @scripting_engine ||= 'Lua 5.4' end # Get pandoc's info by key like a Hash for backwards compatability. # # @deprecated Use Info's getters instead. # # @param key [String|Symbol] the key for the information to look up. # Info only supports keys 'version' and 'data_dir'. # @return [Any] Information associated with the key. # @raise [Error] for an unknown key. def [](key) case key when 'verion', :version version when 'data_dir', :data_dir data_dir when 'scripting_engine', :scripting_engine scripting_engine else throw Error.new "Info does not know key '#{key}'" end end end |
#version ⇒ Array<Integer>
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 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 |
# File 'lib/paru/info.rb', line 35 class Info attr_reader :version, :data_dir, :scripting_engine # Create a new Info object # # @param path [String] the path to pandoc. Defaults to 'pandoc', i.e., # assumes it's on the environment's path. def initialize(path = 'pandoc') # Get pandoc's version information version_string = '' IO.popen("#{path} --version", 'r+') do |p| p.close_write version_string << p.read end # Extract the version as an array of integers, like SemVer. @version = version_string .match(/pandoc.* (\d+\.\d+.*)$/)[1] .split('.') .map(&:to_i) # Extract the data directory @data_dir = version_string.match(/User data directory: (.+)$/)[1] # Extract scripting engine @scripting_engine = version_string.match(/Scripting engine: (.+)$/)[1] rescue StandardError => e warn "Error extracting pandoc's information: #{e.message}" warn 'Using made up values instead.' @version ||= [2, 18] @data_dir ||= '.' @scripting_engine ||= 'Lua 5.4' end # Get pandoc's info by key like a Hash for backwards compatability. # # @deprecated Use Info's getters instead. # # @param key [String|Symbol] the key for the information to look up. # Info only supports keys 'version' and 'data_dir'. # @return [Any] Information associated with the key. # @raise [Error] for an unknown key. def [](key) case key when 'verion', :version version when 'data_dir', :data_dir data_dir when 'scripting_engine', :scripting_engine scripting_engine else throw Error.new "Info does not know key '#{key}'" end end end |
Instance Method Details
#[](key) ⇒ Any
Deprecated.
Use Info’s getters instead.
Get pandoc’s info by key like a Hash for backwards compatability.
Info only supports keys ‘version’ and ‘data_dir’.
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/paru/info.rb', line 78 def [](key) case key when 'verion', :version version when 'data_dir', :data_dir data_dir when 'scripting_engine', :scripting_engine scripting_engine else throw Error.new "Info does not know key '#{key}'" end end |