Class: AsciidocBib::Options
- Inherits:
-
Object
- Object
- AsciidocBib::Options
- Defined in:
- lib/asciidoc-bib/options.rb
Overview
Class to read in asciidoc-bib options from command-line, and store results in an accessible form.
Instance Attribute Summary collapse
-
#bibfile ⇒ Object
readonly
Location of bib file to read references from.
-
#filename ⇒ Object
readonly
Location of file to process.
-
#links ⇒ Object
readonly
Flag to indicate if links should be included.
-
#style ⇒ Object
readonly
Name of style to use for displaying citations and references.
Instance Method Summary collapse
-
#initialize(program_name = 'asciidoc-bib') ⇒ Options
constructor
Sets up options for the program, including: * location of bib file * whether internal links should be added * sorting of references * style of references * name of file to process.
-
#numeric_in_appearance_order? ⇒ Boolean
Convenience method to check @numeric_order.
Constructor Details
#initialize(program_name = 'asciidoc-bib') ⇒ Options
Sets up options for the program, including:
- location of bib file
- whether internal links should be added
- sorting of references
- style of references
- name of file to process
25 26 27 28 29 30 31 32 33 34 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 91 92 93 94 95 |
# File 'lib/asciidoc-bib/options.rb', line 25 def initialize(program_name = 'asciidoc-bib') @bibfile = '' @links = true @numeric_order = :alphabetical @style = AsciidocBib::Styles.default_style = OptionParser.new do |opts| opts. = "Usage: #{program_name} filename" opts.on("-h", "--help", "help message") do |v| puts "#{program_name} #{AsciidocBib::VERSION}" puts puts puts puts "All styles available through CSL are supported." puts "The default style is 'apa'." exit! end opts.on("-b", "--bibfile FILE", "location of bib file") do |v| @bibfile = v end opts.on("-n", "--no-links", "do not add internal links") do |v| @links = false end opts.on('', '--numeric-alphabetic-order', 'sort numeric styles in alphabetical order (DEFAULT)') do |v| @numeric_order = :alphabetical end opts.on('', '--numeric-appearance-order', 'sort numeric styles in order of appearance') do |v| @numeric_order = :appearance end opts.on("-s", "--style STYLE", "reference style") do |v| @style = v end opts.on("-v", "--version", "show version") do |v| puts "#{program_name} version #{AsciidocBib::VERSION}" exit! end end begin .parse! rescue puts exit! end # unless specified by caller, try to find the bibliography if @bibfile.empty? @bibfile = AsciidocBib::FileHandlers.find_bibliography "." if @bibfile.empty? @bibfile = AsciidocBib::FileHandlers.find_bibliography "#{ENV['HOME']}/Documents" end end if @bibfile.empty? puts "Error: could not find a bibliography file" exit end unless AsciidocBib::Styles.valid? @style puts "Error: style #{@style} was not one of the available styles" exit end if ARGV.length == 1 @filename = ARGV[0] else puts "Error: a single file to convert must be given" exit end puts "Reading biblio: #{@bibfile}" puts "Reference style: #{@style}" end |
Instance Attribute Details
#bibfile ⇒ Object (readonly)
Location of bib file to read references from.
10 11 12 |
# File 'lib/asciidoc-bib/options.rb', line 10 def bibfile @bibfile end |
#filename ⇒ Object (readonly)
Location of file to process.
12 13 14 |
# File 'lib/asciidoc-bib/options.rb', line 12 def filename @filename end |
#links ⇒ Object (readonly)
Flag to indicate if links should be included.
14 15 16 |
# File 'lib/asciidoc-bib/options.rb', line 14 def links @links end |
#style ⇒ Object (readonly)
Name of style to use for displaying citations and references.
16 17 18 |
# File 'lib/asciidoc-bib/options.rb', line 16 def style @style end |
Instance Method Details
#numeric_in_appearance_order? ⇒ Boolean
Convenience method to check @numeric_order. This is used in place of making the @numeric_order field visible to external classes.
100 101 102 |
# File 'lib/asciidoc-bib/options.rb', line 100 def numeric_in_appearance_order? @numeric_order == :appearance end |