Class: Mericope::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/mericope/cli.rb

Constant Summary collapse

ALLOWED_COMMANDS =
%w{help normalize parse substitute reverse-substitute usage}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#inputObject (readonly)

Returns the value of attribute input.



6
7
8
# File 'lib/mericope/cli.rb', line 6

def input
  @input
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/mericope/cli.rb', line 6

def options
  @options
end

Class Method Details

.run(command, *args) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/mericope/cli.rb', line 10

def self.run(command, *args)
  if ALLOWED_COMMANDS.member?(command)
    command = command.gsub(/-/, '_').to_sym
    CLI.new(*args).send(command)
  else
    CLI.new(*args).usage
  end
end

Instance Method Details

#helpObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/mericope/cli.rb', line 19

def help
  print <<-HELP

Glossary

  pericope        A Bible reference (e.g. Romans 3:6-11)
  mericope        A Mormon Pericope
  verse ID        An integer that uniquely identifies a Bible verse      

  HELP
end

#normalizeObject



31
32
33
34
35
36
37
38
# File 'lib/mericope/cli.rb', line 31

def normalize
  begin
    mericope = Mericope.new(input)
    print mericope.to_s
  rescue
    print $!.to_s
  end
end

#parseObject



40
41
42
43
44
45
46
47
# File 'lib/mericope/cli.rb', line 40

def parse
  begin
    mericope = Mericope.new(input)
    print mericope.to_a.join("\n")
  rescue
    print $!.to_s
  end
end

#reverse_substituteObject



57
58
59
60
61
62
63
# File 'lib/mericope/cli.rb', line 57

def reverse_substitute
  begin
    print Mericope.rsub(input)
  rescue
    print $!.to_s
  end
end

#substituteObject



49
50
51
52
53
54
55
# File 'lib/mericope/cli.rb', line 49

def substitute
  begin
    print Mericope.sub(input)
  rescue
    print $!.to_s
  end
end

#usageObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/mericope/cli.rb', line 65

def usage
  print <<-USAGE

Usage

  mericope [Command] [Input]

Commands

  help                Prints more information about mericope
  normalize           Accepts a mericope and returns a properly-formatted mericope
  parse               Accepts a mericope and returns a list of verse IDs
  substitute          Accepts a block of text and replaces all mericopes in the text with verse IDs
  reverse-substitute  Accepts a block of text and replaces collections of verse IDs with mericopes
  usage               Prints this message

  USAGE
end